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>
#define ll long long
using namespace std;
const int MAXN = (int) 1e6;
int arr[MAXN + 1];
pair <int, int> nrm[MAXN + 1], aux[MAXN + 1];
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
int l = 1, r = n;
for(i = 1; i <= n; i++) {
cin >> arr[i];
if(arr[i] & 1) {
nrm[r--] = {1, i};
}
else {
nrm[l++] = {0, i};
}
}
int ans = 0;
for(int bit = 0; bit <= 29; bit++) {
ll cur = 0;
int l0 = n, r0 = n;
int l1 = n, r1 = n;
for(i = 1; i <= n; i++) {
while(l0 >= 1 && nrm[i].first + nrm[l0].first >= (1 << bit)) {
l0--;
}
while(r0 >= 1 && nrm[i].first + nrm[r0].first >= (1 << (bit + 1))) {
r0--;
}
while(l1 >= 1 && nrm[i].first + nrm[l1].first >= (1 << (bit + 1)) + (1 << bit)) {
l1--;
}
while(r1 >= 1 && nrm[i].first + nrm[r1].first >= (1 << (bit + 2))) {
r1--;
}
cur += r1 - l1 + r0 - l0;
cur += (((2 * nrm[i].first) & (1 << bit)) > 0);
}
cur /= 2, cur &= 1;
ans += cur * (1 << bit);
int sz = 0;
for(i = 1; i <= n; i++) {
int cur = nrm[i].second;
if((arr[cur] & (1 << (bit + 1))) == 0) {
aux[++sz] = {arr[cur] & ((1 << (bit + 2)) - 1), cur};
}
}
for(i = 1; i <= n; i++) {
int cur = nrm[i].second;
if(arr[cur] & (1 << (bit + 1))) {
aux[++sz] = {arr[cur] & ((1 << (bit + 2)) - 1), cur};
}
}
for(i = 1; i <= n; i++) {
nrm[i] = aux[i];
}
}
cout << ans;
//cin.close();
//cout.close();
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... |