#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 |
1 |
Correct |
4 ms |
620 KB |
Output is correct |
2 |
Correct |
4 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
461 ms |
26564 KB |
Output is correct |
2 |
Correct |
416 ms |
24812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
461 ms |
26564 KB |
Output is correct |
2 |
Correct |
416 ms |
24812 KB |
Output is correct |
3 |
Correct |
533 ms |
28600 KB |
Output is correct |
4 |
Correct |
514 ms |
27756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
620 KB |
Output is correct |
2 |
Correct |
4 ms |
492 KB |
Output is correct |
3 |
Correct |
86 ms |
3436 KB |
Output is correct |
4 |
Correct |
93 ms |
3436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
620 KB |
Output is correct |
2 |
Correct |
4 ms |
492 KB |
Output is correct |
3 |
Correct |
461 ms |
26564 KB |
Output is correct |
4 |
Correct |
416 ms |
24812 KB |
Output is correct |
5 |
Correct |
533 ms |
28600 KB |
Output is correct |
6 |
Correct |
514 ms |
27756 KB |
Output is correct |
7 |
Correct |
86 ms |
3436 KB |
Output is correct |
8 |
Correct |
93 ms |
3436 KB |
Output is correct |
9 |
Correct |
742 ms |
31212 KB |
Output is correct |
10 |
Correct |
750 ms |
31212 KB |
Output is correct |
11 |
Correct |
755 ms |
31180 KB |
Output is correct |