总结
看到这个题,一直在想数学方式,用公式来推,然后就稳稳的死在里面了
解析
思路每一位bit位为1,遍历求每两个数和的奇数个,该位是1
b[j]%(1<<j+1),求模处理无用数据,方便二分求范围,
b[j]=[ 0, 2i+1-1]
b[j]+b[j+1]=[ 0, 2i+2-1]
例如:pos=2,该位1
num+b[j]可能为1的范围:0100-0111 或者1100-1111
所以:[ 2i , 2i+1-1 ] 或者[2i+2i+1 ,2i+2-2]
所以:[ 2i , 2i+1-1 -b[j] ] 或者[2i+2i+1 ,2i+2-2-b[j] ]
题目链接
#include<bits/stdc++.h>
//typedef long long ll;
//#define ull unsigned long long
//#define int long long
#define F first
#define S second
#define endl "\n"//<<flush
#define eps 1e-6
#define lowbit(x) (x&(-x))
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define MAXN 0x7fffffff
#define INF 0x3f3f3f3f3f3f3f3f
#define pa pair<int,int>
#define ferma(a,b) pow(a,b-2)
#define pb push_back
#define all(x) x.begin(),x.end()
#define memset(a,b) memset(a,b,sizeof(a));
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
void file()
{
#ifdef ONLINE_JUDGE
#else
freopen("cin.txt","r",stdin);
// freopen("cout.txt","w",stdout);
#endif
}
int get(int num)
{
return 1<<num;
}
signed main()
{
IOS;
//file();
int n;
cin>>n;
vector<int>a(n),b(n);
for(auto &it:a)
cin>>it;
int ans=0;
for(int i=0;i<26;++i)
{
int mod=get(i+1);
for(int j=0;j<n;++j)
b[j]=a[j]%mod;
long long sum=0;
sort(all(b));
for(int j=0;j<n;++j)
{
int l=lower_bound(all(b),get(i)-b[j])-b.begin();
int r=upper_bound(all(b),get(i+1)-1-b[j])-b.begin()-1;
sum+=r-l+1;
l=lower_bound(all(b),get(i)+get(i+1)-b[j])-b.begin();
r=upper_bound(all(b),get(i+2)-2-b[j])-b.begin()-1;
sum+=r-l+1;
if((b[j]*2)&get(i))
sum--;
}
if(sum/2%2)
ans+=get(i);
}
cout<<ans<<endl;
return 0;
}