#include<bits/stdc++.h>
#define ll long long
#define task " "
using namespace std;
const ll N = 1e6 + 5;
const ll mod = 1e9 + 7;
#define bit(x,y) ((x >> y) & 1)
int a[N],b[N];
pair<ll,int> tmp[N],ntmp[N];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n;
cin >> n;
ll i,j;
for(i = 1;i <= n;i++) cin >> a[i];
ll ans = 0;
for(ll id = 0;id <= 30;id++)
{
if(id == 0)
{
for(i = 1;i <= n;i++) tmp[i] = {(a[i] % (1LL << (id + 1))),i};
sort(tmp + 1,tmp + 1 + n);
}else
{
ll sus = 1;
for(i = 1;i <= n;i++)
{
if(!bit(a[tmp[i].second],id))
{
ntmp[sus++] = tmp[i];
}
}
for(i = 1;i <= n;i++)
{
if(bit(a[tmp[i].second],id))
{
ntmp[sus++] = {tmp[i].first ^ (1LL << id),tmp[i].second};
}
}
swap(ntmp,tmp);
}
for(i = 1;i <= n;i++) b[i] = tmp[i].first;
ll cnt = 0;
ll l = n + 1,r = 0,s = n + 1;
ll t1 = (1LL << id),t2 = (1LL << (id + 1));
if(b[n - 1] + b[n] < t1) break;
for(i = n;i >= 1;i--)
{
if(b[1] + b[i] >= t1) l = i;
else break;
}
for(i = 1;i <= n;i++)
{
if(b[1] + b[i] < t2) r = i;
else break;
}
for(i = n;i >= 1;i--)
{
if(t1 + t2 - b[1] <= b[i]) s = i;
else break;
}
cnt += max(0LL,r - l + 1) + (n - s + 1);
for(i = 2;i <= n;i++)
{
while(l - 1 >= 1 && b[i] + b[l - 1] >= t1) l--;
while(b[i] + b[r] >= t2) r--;
while(s >= 1 && t1 + t2 - b[i] <= b[s - 1]) s--;
cnt += max(0LL,r - max(l,i) + 1) + (n - max(i,s) + 1);
}
if(cnt % 2 == 1) ans = ans ^ (1 << id);
}
cout << ans;
}
Compilation message
xorsum.cpp: In function 'int main()':
xorsum.cpp:16:10: warning: unused variable 'j' [-Wunused-variable]
16 | ll i,j;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
35420 KB |
Output is correct |
2 |
Correct |
63 ms |
35500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
299 ms |
39364 KB |
Output is correct |
2 |
Correct |
273 ms |
39252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
299 ms |
39364 KB |
Output is correct |
2 |
Correct |
273 ms |
39252 KB |
Output is correct |
3 |
Correct |
455 ms |
39508 KB |
Output is correct |
4 |
Correct |
464 ms |
39256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
35420 KB |
Output is correct |
2 |
Correct |
63 ms |
35500 KB |
Output is correct |
3 |
Correct |
148 ms |
35480 KB |
Output is correct |
4 |
Correct |
138 ms |
35416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
35420 KB |
Output is correct |
2 |
Correct |
63 ms |
35500 KB |
Output is correct |
3 |
Correct |
299 ms |
39364 KB |
Output is correct |
4 |
Correct |
273 ms |
39252 KB |
Output is correct |
5 |
Correct |
455 ms |
39508 KB |
Output is correct |
6 |
Correct |
464 ms |
39256 KB |
Output is correct |
7 |
Correct |
148 ms |
35480 KB |
Output is correct |
8 |
Correct |
138 ms |
35416 KB |
Output is correct |
9 |
Correct |
762 ms |
39504 KB |
Output is correct |
10 |
Correct |
758 ms |
39512 KB |
Output is correct |
11 |
Correct |
774 ms |
39364 KB |
Output is correct |