题意:给出长度为n的a数组和x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5),求i,j(1 ≤ i < j ≤ n)的无序对满足a[i]^a[j]=x的个数
题解:n比较大,考虑到a^b=c->a^c=b,b^c=a,可以预存每个值的个数,扫一遍数组,a[i]^x的数在个数里找即可
坑点:x^a[i]=a[i]的情况,要排除自己,答案数会超int,异或值可能超10^5,统计个数的数组要开大一些
#include<cstdio>
#include<cmath>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#include<list>
#define pi 4*atan(1)
#define eps 1e-10
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define FF(i,n) for(int i = 0 ; i < n ; i++)
#define F(i,n) for(int i = 1 ; i <= n ; i++)
#define maxn 100000+10
#define mod 200907
#define met(a) memset(a,0,sizeof(a))
typedef long long LL;
//typedef __int64 LL;
using namespace std;
/*void read(int &x){
#define CH getchar()
char ch; x=0;for(ch=CH;ch<'0'||ch>'9';ch=CH);
for(;ch>='0'&&ch<='9';x=x*10+ch-48,ch=CH);
}*/
int a[100010];
int cnt[400010];
int main()
{
//ios::sync_with_stdio(false);
//cin.tie(0);
int n,x;
while(cin>>n>>x)
{
int _;
LL ans=0;
met(cnt);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
cnt[a[i]]++;
}
for(int i=1;i<=n;i++)
{
int _=a[i]^x;
ans+=cnt[_];
if(_==a[i])ans--;
}
cout<<ans/2<<endl;
}
return 0;
}