Source Code
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <iostream>
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define p_b push_back
#define all(c) c.begin(), c.end()
#define mem(array, some_data) memset(array, some_data, sizeof array);
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; //printf("%lld ", ll); to out put long
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tree<int ,null_type,less<int >,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const double eps = 1e-6;
const int MAXN = 2e5 + 3;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
bool ODD(ll O)
{
    return (O % 2 != 0);
}

ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}
int dx[] = {1, 0, -1, 0,-1, 1, -1, 1};
int dy[] = {0, 1, 0, -1,-1, 1, 1, -1};

bool is_power_of_2(int x) {
    if(x == 0) return true;
    return (ceil(log2(x)) == floor(log2(x)));
}
/*------ never give up --------*/

string to_bin(int x) {
    string ret = "";
    while(x) {
        if(ODD(x)) ret += "1";
        else ret += "0";
        x /= 2;
    }
    while(ret.size() <= 40) ret += "0";
    reverse(all(ret));
    return ret;
}
bool have_d_and(int x, int d) {
    string dd = to_bin(d), xx = to_bin(x);
    for(int i = 0; i < dd.size(); i++) {
        if(dd[i] == '1') {
            if(xx[i] == '0') return false;
        }
    }
    return 1;
}
bool have_d_or(int x, int d) {
    string dd = to_bin(d), xx = to_bin(x);
    for(int i = 0; i < dd.size(); i++) {
        if(dd[i] == '0') {
            if(xx[i] == '1') return false;
        }
    }
    return 1;
}

void solve(int test_case)
{

    int n, d;
    cin >> n >> d;
    vector <int> vc;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if(have_d_and(x , d)) vc.push_back(x);
    }
    vector <int> ans;
    for(int i : vc) {
        if(have_d_or(i , d)) ans.push_back(i);
    }
    if(d && ans.size()) {
        if(ODD(ans.size())) cout << ans.size();
        else cout << ans.size() - 1;
        return;
    }
    cout << ans.size();


}
int main()
{

    //ios_base::sync_with_stdio(0); cin.tie(0);
    int n = 1;
    //cin >> n;

    while (n--)
    {

        solve(n);
    }

    return 0;
}
Copy
Legendary OBITO
GNU G++17
280 ms
2.6 MB
Accepted