#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define test(x) cout << #x << ' ' << x << endl
#define printv(x) { \
for (auto a : x) cout << a << ' '; \
cout << endl; \
}
#define pii pair<int, int>
#define pll pair<lli, lli>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const int N = 200000, abc = 864197532;
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector <int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
sort(all(a));
int ans = 0;
for (int k = 29; ~k; --k) {
int p = -1;
for (int i = 0; i < n; ++i) if (a[i] >= (1 << k + 1)) {
if (p == -1) p = i;
a[i] -= (1 << k + 1);
}
if (~p) {
vector <int> b;
int i, j;
for (i = 0, j = p; i < p && j < n; ) {
if (a[i] < a[j]) b.pb(a[i++]);
else b.pb(a[j++]);
}
while (i < p) b.pb(a[i++]);
while (j < n) b.pb(a[j++]);
a = b;
}
int cnt = 0;
for (int i = 0, r1 = n, l1 = n, l2 = n; i < n; ++i) {
while (r1 && (1 << k + 1) - a[i] <= a[r1 - 1]) r1--;
while (l1 && (1 << k) - a[i] <= a[l1 - 1]) l1--;
int r = max(r1 - i, 0), l = max(l1 - i, 0);
cnt ^= (r - l) & 1;
while (l2 && 3 * (1 << k) - a[i] <= a[l2 - 1]) l2--;
r = n - i;
l = max(l2 - i, 0);
cnt ^= (r - l) & 1;
}
/*
* check k bit
* mod 2^{k + 1}
* 1 3
* count pair 2^k - a <= b < 2^{k + 1} - a
* 3 * 2^k - a > b
*/
if (cnt) ans |= 1 << k;
}
cout << ans << endl;
}
Compilation message
xorsum.cpp: In function 'int main()':
xorsum.cpp:31:57: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
31 | for (int i = 0; i < n; ++i) if (a[i] >= (1 << k + 1)) {
| ~~^~~
xorsum.cpp:33:29: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
33 | a[i] -= (1 << k + 1);
| ~~^~~
xorsum.cpp:48:34: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
48 | while (r1 && (1 << k + 1) - a[i] <= a[r1 - 1]) r1--;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
332 KB |
Output is correct |
2 |
Correct |
5 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
532 ms |
12260 KB |
Output is correct |
2 |
Correct |
440 ms |
11728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
532 ms |
12260 KB |
Output is correct |
2 |
Correct |
440 ms |
11728 KB |
Output is correct |
3 |
Correct |
653 ms |
12252 KB |
Output is correct |
4 |
Correct |
664 ms |
18596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
332 KB |
Output is correct |
2 |
Correct |
5 ms |
332 KB |
Output is correct |
3 |
Correct |
97 ms |
1608 KB |
Output is correct |
4 |
Correct |
98 ms |
1648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
332 KB |
Output is correct |
2 |
Correct |
5 ms |
332 KB |
Output is correct |
3 |
Correct |
532 ms |
12260 KB |
Output is correct |
4 |
Correct |
440 ms |
11728 KB |
Output is correct |
5 |
Correct |
653 ms |
12252 KB |
Output is correct |
6 |
Correct |
664 ms |
18596 KB |
Output is correct |
7 |
Correct |
97 ms |
1608 KB |
Output is correct |
8 |
Correct |
98 ms |
1648 KB |
Output is correct |
9 |
Correct |
952 ms |
21608 KB |
Output is correct |
10 |
Correct |
970 ms |
21696 KB |
Output is correct |
11 |
Correct |
968 ms |
21944 KB |
Output is correct |