#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int arr[maxn], n;
int A[maxn], B[maxn], p1, p2;
int check() {
int ret = 0;
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++)
ret ^= arr[i] + arr[j];
return ret;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> arr[i];
int ans = 0;
for (int i = 0; i < 30; i++) {
int R = (1<<i) - 1;
p1 = p2 = 0;
for (int j = 1; j <= n; j++)
if ((arr[j]>>i)&1) B[++p2] = arr[j];
else A[++p1] = arr[j];
int ptr = p1 + 1;
for (int j = 1; j <= p1; j++) {
while (ptr > j && (A[j]&R) + (A[ptr-1]&R) >= (1<<i)) ptr--;
if (ptr < j) ptr = j;
if ((p1-ptr+1)&1) ans ^= (1<<i);
}
ptr = p2 + 1;
for (int j = 1; j <= p2; j++) {
while (ptr > j && (B[j]&R) + (B[ptr-1]&R) >= (1<<i)) ptr--;
if (ptr < j) ptr = j;
if ((p2-ptr+1)&1) ans ^= (1<<i);
}
ptr = p2;
for (int j = 1; j <= p1; j++) {
while (ptr && (A[j]&R)+(B[ptr]&R) >= (1<<i)) ptr--;
if (ptr&1) ans ^= (1<<i);
}
for (int j = 1; j <= p1; j++) arr[j] = A[j];
for (int j = 1; j <= p2; j++) arr[p1 + j] = B[j];
}
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
308 ms |
15672 KB |
Output is correct |
2 |
Correct |
271 ms |
14528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
308 ms |
15672 KB |
Output is correct |
2 |
Correct |
271 ms |
14528 KB |
Output is correct |
3 |
Correct |
400 ms |
17760 KB |
Output is correct |
4 |
Correct |
372 ms |
17188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
60 ms |
2232 KB |
Output is correct |
4 |
Correct |
61 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
308 ms |
15672 KB |
Output is correct |
4 |
Correct |
271 ms |
14528 KB |
Output is correct |
5 |
Correct |
400 ms |
17760 KB |
Output is correct |
6 |
Correct |
372 ms |
17188 KB |
Output is correct |
7 |
Correct |
60 ms |
2232 KB |
Output is correct |
8 |
Correct |
61 ms |
2304 KB |
Output is correct |
9 |
Correct |
540 ms |
20412 KB |
Output is correct |
10 |
Correct |
546 ms |
20368 KB |
Output is correct |
11 |
Correct |
548 ms |
20420 KB |
Output is correct |