#include<iostream>
#include<cassert>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
#include<set>
#include<queue>
#include<map>
using namespace std;
const int N = (int)1e6 + 7;
const int M = (int)1e6 + 7;
const int inf = (int)1e9 + 7;
const int MOD = (int)998244353;
const long long INF = (long long)1e18 + 7;
int mult(int x, int y) {
return 1ll*x*y%MOD;
}
int sum(int x, int y) {
x += y;
if(x >= MOD) {
x -= MOD;
}
return x;
}
int sub(int x, int y) {
x -= y;
if(x < 0) {
x += MOD;
}
return x;
}
int n, a[N], b[N];
long long f(int l, int r) {
long long cur = 0;
int j = 0, k = 0;
for(int i = n; i >= 1; --i) {
while(k<n && a[k+1] <= r-a[i]) {
k++;
}
while(j<n && a[j+1] < l-a[i]) {
j++;
}
cur += min(i, k)-min(i, j);
}
return cur;
}
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
}
int ans = 0;
sort(a+1, a+1+n);
for(int j = 29; j >= 0; --j) {
long long cur = f((1 << j), (1 << (j+1))-1) + f((1 << j) + (1 << (j+1)), (1 << (j+2))-1);
if(cur&1) {
ans |= (1 << j);
}
vector<int> c, d, e(n);
for(int i = 1; i <= n; ++i) {
if(a[i] >> j & 1) {
c.push_back(a[i]^(1<<j));
} else {
d.push_back(a[i]);
}
}
merge(c.begin(), c.end(), d.begin(), d.end(), e.begin());
assert((int)e.size() == n);
for(int i = 1; i <= n; ++i) {
a[i] = e[i-1];
}
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2396 KB |
Output is correct |
2 |
Correct |
3 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
393 ms |
18004 KB |
Output is correct |
2 |
Correct |
363 ms |
17208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
393 ms |
18004 KB |
Output is correct |
2 |
Correct |
363 ms |
17208 KB |
Output is correct |
3 |
Correct |
479 ms |
17984 KB |
Output is correct |
4 |
Correct |
473 ms |
17588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2396 KB |
Output is correct |
2 |
Correct |
3 ms |
2396 KB |
Output is correct |
3 |
Correct |
71 ms |
5656 KB |
Output is correct |
4 |
Correct |
73 ms |
5712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2396 KB |
Output is correct |
2 |
Correct |
3 ms |
2396 KB |
Output is correct |
3 |
Correct |
393 ms |
18004 KB |
Output is correct |
4 |
Correct |
363 ms |
17208 KB |
Output is correct |
5 |
Correct |
479 ms |
17984 KB |
Output is correct |
6 |
Correct |
473 ms |
17588 KB |
Output is correct |
7 |
Correct |
71 ms |
5656 KB |
Output is correct |
8 |
Correct |
73 ms |
5712 KB |
Output is correct |
9 |
Correct |
686 ms |
18268 KB |
Output is correct |
10 |
Correct |
688 ms |
27236 KB |
Output is correct |
11 |
Correct |
685 ms |
27616 KB |
Output is correct |