#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;
for(i = 1; i <= n; i++) {
cin >> arr[i];
nrm[i] = {arr[i] & 1, i};
}
sort(nrm + 1, nrm + n + 1);
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
986 ms |
24500 KB |
Output is correct |
2 |
Correct |
954 ms |
22812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
986 ms |
24500 KB |
Output is correct |
2 |
Correct |
954 ms |
22812 KB |
Output is correct |
3 |
Correct |
1329 ms |
26772 KB |
Output is correct |
4 |
Correct |
1163 ms |
25720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
122 ms |
3192 KB |
Output is correct |
4 |
Correct |
124 ms |
3320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
986 ms |
24500 KB |
Output is correct |
4 |
Correct |
954 ms |
22812 KB |
Output is correct |
5 |
Correct |
1329 ms |
26772 KB |
Output is correct |
6 |
Correct |
1163 ms |
25720 KB |
Output is correct |
7 |
Correct |
122 ms |
3192 KB |
Output is correct |
8 |
Correct |
124 ms |
3320 KB |
Output is correct |
9 |
Correct |
1482 ms |
29452 KB |
Output is correct |
10 |
Correct |
1551 ms |
29432 KB |
Output is correct |
11 |
Execution timed out |
1649 ms |
29404 KB |
Time limit exceeded |