// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
int n, a[1000005];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int ans = 0;
for (int i = 0; i < 30; i++) {
vector <int> v;
int mx = 0;
for (int j = 1; j <= n; j++) {
int x = a[j] % (1ll<<(i + 1));
mx = max(mx, a[j]);
v.push_back(x);
}
if (i && mx < (1ll<<(i - 1))) break;
sort(v.begin(), v.end());
long long tmp = 0, tmp2 = 0;
for (int j = 1; j <= n; j++) {
int x = a[j] % (1ll<<(i + 1));
int l = (1ll<<i) - x, r = (1ll<<(i + 1)) - 1 - x;
if(l >= 0) {
tmp += upper_bound(v.begin(), v.end(), r) - lower_bound(v.begin(), v.end(), l);
if (l <= x && x <= r) tmp--, tmp2++;
}
else {
tmp += v.end() - lower_bound(v.begin(), v.end(), l + (1ll<<(i + 1)));
tmp += upper_bound(v.begin(), v.end(), r) - v.begin();
if (x <= r || x >= l + (1ll<<(i + 1))) tmp--, tmp2++;
}
//cout << tmp << ' ';
}
tmp /= 2; tmp += tmp2;
//cout << tmp << '\n';
//tmp /= 2;
if (tmp & 1) ans ^= (1ll<<i);
}
cout << ans;
}
| # | 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... |