Codeforces Round #383 (Div. 2) B

题意:给出长度为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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值