This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
// 0 <= x, y <= 2^(k+1)
// (x+y) & (2^k) > 0
// 2^k <= x+y < 2^(k+1)
// 2^(k+1) <= x+y < 2^(k+2)
int main()
{
ios :: sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> v(n);
for (int &x : v)
cin >> x;
int res = 0;
for (int k = 0; k < 30; ++k)
{
// radix sort
{
vector<int> a, b;
for (int &x : v)
{
if (x >> k & 1) b.pb(x);
else a.pb(x);
}
v.clear();
for (int x : a)
v.pb(x);
for (int x : b)
v.pb(x);
}
ll C = 0;
int R = (1 << (k+1)) - 1;
int l = n-1, r = n-1;
for (int i = 0; i < n; ++i)
{
while (l >= 0 && (v[i] & R) + (v[l] & R) >= (1 << k)) l--;
while (r >= 0 && (v[i] & R) + (v[r] & R) >= (1 << (k+1))) r--;
C += max(0, r - max(l, i-1));
}
l = r = n-1;
for (int i = 0; i < n; ++i)
{
while (l >= 0 && (v[i] & R) + (v[l] & R) >= (1 << (k+1)) + (1 << k)) l--;
while (r >= 0 && (v[i] & R) + (v[r] & R) >= (1 << (k+1)) + (1 << (k+1))) r--;
C += max(0, r - max(l, i-1));
}
if (C & 1) res ^= (1 << k);
}
cout << res << '\n';
return 0;
}
# | 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... |