标签:oid 排序 http test int == typedef def ORC
题目链接:https://codeforces.com/contest/1323/problem/D
题意:给了大小为4e5的数组a,其中1<=ai<=1e7。求所有点对和的异或和,即:
思路:
AC code:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn=4e5+5; typedef long long LL; int n,a[maxn],b[maxn],p[30],ans,MOD; void init(){ p[0]=1; for(int i=1;i<=26;++i) p[i]=p[i-1]<<1; } int bs1(int ll,int rr,int v){ int l=ll,r=rr,mid; while(l<=r){ mid=(l+r)>>1; if(b[mid]>=v) r=mid-1; else l=mid+1; } return l; } int bs2(int ll,int rr,int v){ int l=ll,r=rr,mid; while(l<=r){ mid=(l+r)>>1; if(b[mid]<=v) l=mid+1; else r=mid-1; } return r; } int main(){ init(); scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",&a[i]); for(int k=0;k<=24;++k){ LL num=0; MOD=p[k+1]; for(int i=1;i<=n;++i) b[i]=a[i]%MOD; sort(b+1,b+n+1); for(int i=1;i<n;++i){ int le=max(p[k]-b[i],0),ri=p[k+1]-1-b[i]; int l=bs1(i+1,n,le); int r=bs2(i+1,n,ri); num+=(LL)(r-l+1); if(b[i]<=p[k]) continue; le=p[k+1]+p[k]-b[i],ri=p[k+2]-2-b[i]; l=bs1(i+1,n,le); r=bs2(i+1,n,ri); num+=(LL)(r-l+1); } if((int)(num%2)==1) ans+=p[k]; } printf("%d\n",ans); return 0; }
Codeforces Round #626 Div2 D. Present(位掩码,二分)
标签:oid 排序 http test int == typedef def ORC
原文地址:https://www.cnblogs.com/FrankChen831X/p/12442160.html