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;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tpl;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<int> a(n), ord(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
ord[i] = i;
}
int ans = 0;
for (int bit = 0; bit < 30; bit++) {
// sort
vector<int> zeroBit, oneBit, vec(n);
for (int u : ord) {
if ((a[u] >> bit) & 1) oneBit.push_back(u);
else zeroBit.push_back(u);
}
ord = zeroBit, ord.insert(ord.end(), all(oneBit));
// last (`bit` + 1) bits
for (int i = 0; i < n; i++)
vec[i] = a[ord[i]] & ((1 << (bit + 1)) - 1);
// calculate
int zero = -1, one = -1, two = -1;
for (int i = (int)ord.size() - 1; i >= 0; i--) {
zero = min(zero, i), one = min(one, i), two = min(two, i);
while (zero + 1 <= i && ((vec[zero + 1] + vec[i]) >> bit) <= 0) zero++;
while (one + 1 <= i && ((vec[one + 1] + vec[i]) >> bit) <= 1) one++;
while (two + 1 <= i && ((vec[two + 1] + vec[i]) >> bit) <= 2) two++;
int cntOne = one - zero + i - two;
if (cntOne & 1) ans ^= (1 << bit);
}
}
cout << ans << "\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... |