Codeforces Round #626 Div. 2 D. Present(二分 状态压缩)
https://codeforces.com/contest/1323/problem/D
上个题解....
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 4e5+5; 5 int a[maxn],b[maxn]; 6 int n; 7 int main(){ 8 scanf("%d",&n); 9 int ans = 0; 10 for(int i = 1;i<=n;i++) scanf("%d",&a[i]); 11 for(int i = 0;i<25;i++){ //最多25位 12 for(int j = 1;j<=n;j++) b[j] = a[j]%(1<<(i+1)); 13 sort(b+1,b+1+n); 14 for(int j = 1;j<=n;j++){ 15 int l = max(0,(1<<i)-b[j]);//第一段区间的左端点 16 int r = ( (1<<(i+1) ) - 1) - b[j] ;//第一段区间的右端点 17 int range = upper_bound(b+1,b+j,r)-lower_bound(b+1,b+j,l); 18 if(range&1) ans^=(1<<i); 19 l = max(0,( (1<<(i+1)) +(1<<i)-b[j] ) );//第二段区间的左端点 20 r = ( (1<<(i+2)) -1)-b[j];//第二段区间的右端点 21 range = upper_bound(b+1,b+j,r)-lower_bound(b+1,b+j,l); 22 if(range&1) ans^=(1<<i); 23 //用二分求出区间长度range 24 } 25 } 26 printf("%d",ans); 27 return 0; 28 }