#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;
int l = 1, r = n;
for(i = 1; i <= n; i++) {
cin >> arr[i];
if(arr[i] & 1) {
nrm[r--] = {1, i};
}
else {
nrm[l++] = {0, i};
}
}
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 |
7 ms |
512 KB |
Output is correct |
2 |
Correct |
8 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
903 ms |
19940 KB |
Output is correct |
2 |
Correct |
852 ms |
18620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
903 ms |
19940 KB |
Output is correct |
2 |
Correct |
852 ms |
18620 KB |
Output is correct |
3 |
Correct |
1043 ms |
20040 KB |
Output is correct |
4 |
Correct |
1110 ms |
19320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
512 KB |
Output is correct |
2 |
Correct |
8 ms |
384 KB |
Output is correct |
3 |
Correct |
117 ms |
2372 KB |
Output is correct |
4 |
Correct |
126 ms |
2296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
512 KB |
Output is correct |
2 |
Correct |
8 ms |
384 KB |
Output is correct |
3 |
Correct |
903 ms |
19940 KB |
Output is correct |
4 |
Correct |
852 ms |
18620 KB |
Output is correct |
5 |
Correct |
1043 ms |
20040 KB |
Output is correct |
6 |
Correct |
1110 ms |
19320 KB |
Output is correct |
7 |
Correct |
117 ms |
2372 KB |
Output is correct |
8 |
Correct |
126 ms |
2296 KB |
Output is correct |
9 |
Correct |
1370 ms |
20060 KB |
Output is correct |
10 |
Correct |
1451 ms |
19960 KB |
Output is correct |
11 |
Incorrect |
1265 ms |
20060 KB |
Output isn't correct |