#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define For(i,l,r) for(int i=l;i<=r;i++)
#define ForD(i,r,l) for(int i=r;i>=l;i--)
#define REP(i,l,r) For(i,l,r-1)
#define PER(i,r,l) ForD(i,r-1,l)
#define ff first
#define ss second
#define pb emplace_back
#define all(x) x.begin(),x.end()
#define All(x,n) x+1,x+1+n
#define Alll(x,n) x,x+n
#define sz(a) (signed)a.size()
#ifdef NCGM
#include"debug.h"
#else
#define debug(...) "fr";
#endif
using namespace std;
ll ans=0;
const int N=1e6+2;
int n,a[N];
pair<ll,int> t[N],t1[N],t2[N];
int cnt(int x) {
int l=1,r=n;
int res=0;
while(l<r) {
if (t[l].ff+t[r].ff<=x) {
res+=(r-l);
l++;
} else r--;
}
For(i,1,n) if (t[i].ff*2<=x) res++;
return res;
}
int cntr(int l,int r) {
if (r<l) return 0;
return cnt(r)-cnt(l-1);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
For(i,1,n) cin >> a[i];
int cur=0;
For(i,1,n) t[++cur]=make_pair(a[i]%2,i);
sort(t+1,t+1+n);
For(i,0,29) {
if (i>0) {
int x=0,y=0;
For(j,1,n) {
if ((a[t[j].ss]>>i)&1) t1[++x]=make_pair(t[j].ff+(1<<i),t[j].ss);
else t2[++y]=t[j];
}
For(j,1,y) t[j]=t2[j];
For(j,1,x) t[j+y]=t1[j];
}
ll tmp=cntr((1LL<<i),(1LL<<(i+1))-1);
tmp+=cntr((1LL<<i+1)+(1LL<<i),(1LL<<i+2)-2);
if (tmp%2) ans+=(1LL<<i);
}
cout << ans;
return 0;
}
Compilation message
xorsum.cpp: In function 'int main()':
xorsum.cpp:63:26: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
63 | tmp+=cntr((1LL<<i+1)+(1LL<<i),(1LL<<i+2)-2);
| ~^~
xorsum.cpp:63:46: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
63 | tmp+=cntr((1LL<<i+1)+(1LL<<i),(1LL<<i+2)-2);
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
604 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
489 ms |
47832 KB |
Output is correct |
2 |
Correct |
439 ms |
44744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
489 ms |
47832 KB |
Output is correct |
2 |
Correct |
439 ms |
44744 KB |
Output is correct |
3 |
Correct |
536 ms |
50120 KB |
Output is correct |
4 |
Correct |
504 ms |
48448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
604 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
62 ms |
5600 KB |
Output is correct |
4 |
Correct |
63 ms |
5552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
604 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
489 ms |
47832 KB |
Output is correct |
4 |
Correct |
439 ms |
44744 KB |
Output is correct |
5 |
Correct |
536 ms |
50120 KB |
Output is correct |
6 |
Correct |
504 ms |
48448 KB |
Output is correct |
7 |
Correct |
62 ms |
5600 KB |
Output is correct |
8 |
Correct |
63 ms |
5552 KB |
Output is correct |
9 |
Correct |
695 ms |
52820 KB |
Output is correct |
10 |
Correct |
662 ms |
52616 KB |
Output is correct |
11 |
Correct |
649 ms |
52604 KB |
Output is correct |