#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N=1e6+5;
int a[N],s[N],n,cnt,c[2],ans,cur,pos[N],f[2][N];
inline int readInt() {
int ans=0;
char ch=getchar_unlocked();
bool f=0;
while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar_unlocked();}
while(ch>='0'&&ch<='9'){ans=(ans<<3)+(ans<<1)+ch-'0';ch=getchar_unlocked();}
return f?ans:-ans;
}
main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
n=readInt();
for(int k=1;k<=n;k++){
a[k]=readInt(); pos[k]=k;
cnt+=c[(a[k]&1)^1];
c[a[k]&1]++;
s[k]=a[k]&1;
}
if(cnt%2) ans=1;
int i=0;
c[1]=c[0]=0;
for(int k=1;k<=n;k++){
int b = ((1<<i)&a[pos[k]]);
b=min(b,1);
c[b]++;
f[b][c[b]]=pos[k];
}
cur=0;
for(int j=0;j<=1;j++){
for(int k=1;k<=c[j];k++){
cur++;
pos[cur]=f[j][k];
}
}
for(int i=1;i<=30;i++){
c[1]=c[0]=0;
for(int k=1;k<=n;k++){
int b = ((1<<i)&a[pos[k]]);
b=min(b,1);
c[b]++;
f[b][c[b]]=pos[k];
}
cur=0;
for(int j=0;j<=1;j++){
for(int k=1;k<=c[j];k++){
cur++;
pos[cur]=f[j][k];
}
}
for(int k=1;k<=n;k++)
s[k]+=a[k]&(1ll<<i);
cnt=0;
int l=n,r=n,l1=n,r1=n;
for(int k=1;k<=n;k++){
while(r && s[pos[r]] + s[pos[k]] >= (1<<(i+1)) ) r--;
while(l && s[pos[l]] + s[pos[k]] >= (1<<i) ) l--;
cnt += r-l; cnt %=4;
while( l1&&s[pos[l1]] + s[pos[k]] >=((1<<(i+1))+(1<<i)) ) l1--;
cnt+=n-l1; cnt%=4;
}
int c1=0;
for(int k=1;k<=n;k++){
if((2*a[k])&(1<<i)) c1++;
}
c1%=4;
if((c1+(cnt-c1+4)/2)%2==1) ans+=1<<i;
}
cout<<ans;
}
Compilation message
xorsum.cpp:15:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
15 | main(){
| ^
xorsum.cpp: In function 'int main()':
xorsum.cpp:59:20: warning: unused variable 'r1' [-Wunused-variable]
59 | int l=n,r=n,l1=n,r1=n;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |