Source Code
#include<iostream>
using namespace std;

#include<stack>
#include<queue>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include <functional>
#include<map>
#include<iomanip>
#include<cmath>
#include<list>




#define fst ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef unsigned long long ull;
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define pii pair<int,int>
#define vll vector<ll>
#define fin(i,v) for(ll i=0;i<v.size();i++)
#define go(x,y) for(int i=x;i<=y;i++)
#define MOD 1e9+7
#define out(x) cout << x << endl
#define mii map<int,int>
#define mp map<int,double>
#define loop(mp) for(auto i=mp.begin();i!=mp.end();i++)
#define mm(arr) memset(arr, 0, sizeof(arr))
#define mp(x,y) make_pair(x,y)

#define two2n(n) (1<<n)
constexpr auto PI = 3.14159265358979323846;;



bool ispow(unsigned long long x)
{
	return (x != 0) && ((x & (x - 1)) == 0);
}


bool how(pair<char, int>& a, pair<char, int>& b)
{
	return (a.second < b.second); /* || (a.first == b.first && a.second < b.second));*/
}


/*
		auto start = high_resolution_clock::now();
		auto stop = high_resolution_clock::now();
		auto duration = duration_cast<microseconds>(stop - start);
		cout << "time needed is : " << fixed << setprecision(8) << duration.count() << "   microseconds" << endl;

*/


bool isprime(ll n)
{
	if (n <= 1)
		return false;


	for (int i = 2; i <= sqrt(n); i++)
		if (n % i == 0)
			return false;

	return true;
}

void primeinrange(ll n)
{
	vll v(n, 1);
	v[0] = 0;
	v[1] = 0;

	ll i = 2;
	ll k = 0;
	while (i * i <= n)
	{
		if (v[i] == 0)
		{
			i++;
			continue;
		}
		ll j = 2 * i;
		while (j < n)
		{
			v[j] = 0;
			j += i;
		}
		i++;
	}

	for (int i = 1; i < n; i++)
		if (v[i] == 1)
			k++;
	cout << k << endl;
	for (int i = 1; i < n; i++)
		if (v[i] == 1)
			cout << i << " ";
}
int dash(vector<int>& v, int l, int r, int val)
{
	if (l > r)
		return 0;
	int m = (l + r) / 2;

	v[m] = val;
	dash(v, m + 1, r, val - 1);
	dash(v, l, m - 1, val - 1);

	return 0;
}
void print(int x)
{
	int n = pow(2, x) - 1;
	vector<int>v(n);
	dash(v, 0, n - 1, x);

	for (int i = 0; i < n; i++)
	{
		for (int k = 0; k < v[i]; k++)
			cout << "-";

		cout << endl;
	}
}
int main()
{

	//freopen("tank.in", "r", stdin);
	//freopen("output.txt", "w", stdout);
	fst;


	ll n, d;
	cin >> n >> d;
	vi v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];

	ll ans = 0;

	sort(all(v));
	int j = v.size() - 1;
	if (d < v[v.size() - 1])
	{
		while (v[j] > d)
		{
			j--;
		}
	}
	bool exi = false;
	if (v[j] == d)
	{
		exi = true;
	}
	set<int>poss;
	if (exi)
	{
		ans++;
		ll an = d, oor = d, xoor = d;
		for (int i = 0; i <= j; i++)
		{
			if ((an & v[i]) == d && (oor | v[i]) == d && (xoor ^ v[i]) == d)
			{
				ans++;
				an = (an & v[i]);
				oor = (oor | v[i]);
				xoor = (xoor ^ v[i]);
			}
		}

		cout << ans << endl;
	}
	else
	{


		ll an = d, oor = d, xoor = d;
		for (int i = 0; i <= j; i++)
		{
			if ((an & v[i]) == d && (oor | v[i]) == d && (xoor ^ v[i]) == d)
			{
				ans++;
				an = (an & v[i]);
				oor = (oor | v[i]);
				xoor = (xoor ^ v[i]);
			}
		}

		cout << ans << endl;

		/*
		for (int i = 0; i < n;i++)
		{
			ll an = v[i], oor = v[i], xoor = v[i], temp = 1;
			int j = i+1;
			while (j < n)
			{
				if (an == d && oor == d && xoor == d)
					break;
				an = (an & v[i]);
				oor = (oor | v[i]);
				xoor = (xoor ^ v[i]);
				temp++;
				j++;
			}
			if (an == d && oor==d && xoor ==d)
			{
				ans = max(ans, temp);
				while (j < n && (an == d && oor == d && xoor == d))
				{
					an = (an & v[i]);
					oor = (oor | v[i]);
					xoor = (xoor ^ v[i]);
					temp++;
					j++;
				}
				ans = max(ans, temp - 1);
			}
		}
		*/

	}



	return 0;
}
Copy
Legendary M_kmail
GNU G++17
2 ms
788 KB
Wrong Answer