이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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],pwr[35];
main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n;
for(int i=0;i<=32;i++)
pwr[i]=1<<i;
for(int k=1;k<=n;k++){
cin>>a[k]; 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 = (pwr[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 = ((pwr[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]&pwr[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]] >= (pwr[i+1]) ) r--;
while(l && s[pos[l]] + s[pos[k]] >= pwr[i]) l--;
cnt += r-l; cnt %=4;
while( l1&&s[pos[l1]] + s[pos[k]] >=(pwr[i+1]+pwr[i]) ) l1--;
cnt+=n-l1; cnt%=4;
}
int c1=0;
for(int k=1;k<=n;k++){
if((2*a[k])&pwr[i]) c1++;
}
c1%=4;
if((c1+(cnt-c1+4)/2)%2==1) ans+=pwr[i];
}
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
xorsum.cpp:7:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
7 | main(){
| ^
xorsum.cpp: In function 'int main()':
xorsum.cpp:53:20: warning: unused variable 'r1' [-Wunused-variable]
53 | int l=n,r=n,l1=n,r1=n;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |