This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifdef LC
#include "pch.h"
#else
#include <bits/stdc++.h>
#endif
using namespace std;
using ll = long long;
#define int ll
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple
/*
bit = 0
oth = 1 && carry = 0
OR
oth = 0 && carry = 1
bit = 1
oth = 0 && carry = 0
OR
oth = 1 && carry = 1
*/
int solve(int a[], int an, int b[], int bn, int msk, bool carry) {
int answer = 0;
int j = 0;
for (int i = an; i--; ) {
while (j < bn && (a[i] & msk) + (b[j] & msk) <= msk) {
++j;
}
if (!carry) {
answer += j;
} else {
answer += bn - j;
}
}
return answer;
}
const int N = 1e6 + 10;
int n;
int a[N];
int bs[2];
int b[2][N];
signed main() {
#ifdef LC
assert(freopen("input.txt", "r", stdin));
#endif
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int answer = 0;
for (int l = 0; l < 30; ++l) {
// cout << "l = " << l << endl;
// for (int i = 0; i < n; ++i) {
// cout << ((a[i] >> l) & 1) << " " << (a[i] & ((1 << l) - 1)) << endl;
// }
// cout << "---" << endl;
int msk = (1 << l) - 1;
bs[0] = bs[1] = 0;
for (int i = 0; i < n; ++i) {
int bit = (a[i] >> l) & 1;
b[bit][bs[bit]++] = a[i];
}
copy_n(b[0], bs[0], a);
copy_n(b[1], bs[1], a + bs[0]);
int ones = 0;
for (int i = 0; i < n; ++i) {
if (((a[i] + a[i]) >> l) & 1) {
++ones;
}
}
ones += solve(b[0], bs[0], b[0], bs[0], msk, true);
ones += solve(b[0], bs[0], b[1], bs[1], msk, false);
ones += solve(b[1], bs[1], b[0], bs[0], msk, false);
ones += solve(b[1], bs[1], b[1], bs[1], msk, true);
assert(ones % 2 == 0);
ones /= 2;
if (ones % 2) {
answer ^= 1 << l;
}
}
cout << answer << endl;
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... |