//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) (int)a.size()
#define s second
#define f first
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<pii> rid = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
vector<pii> dir = {{-1, -1}, {-1, 1}, {1, -1}, {1, 1}};
const int N = 2e5 + 1, mod = 1e9 + 7;
const ll inf = 2e18;
double eps = 1e-15;
bool flg = 0;
void slv() {
int n;
cin >> n;
int a[n + 1];
vector<pii> vl;
for (int i = 1; i <= n; i++) {
cin >> a[i];
vl.push_back({0, a[i]});
}
int ans = 0;
for (int b = 0; b < 30; b++) {
vector<int> s[2];
vector<pii> h, nv;
for (int i = 0; i < n; i++) {
if (b && (vl[i].s >> (b - 1) & 1)) {
vl[i].f += (1 << (b - 1));
h.push_back(vl[i]);
}else {
nv.push_back(vl[i]);
s[vl[i].s >> b & 1].push_back(vl[i].f);
}
}
for (auto x: h) {
nv.push_back(x);
s[x.s >> b & 1].push_back(x.f);
}
vl = nv;
int pos = sz(s[0]) - 1;
for (int i = 0; i < sz(s[0]); i++) {
int vl = (1 << b) - s[0][i];
while (pos >= i && s[0][pos] >= vl) pos--;
while (pos < i - 1) pos++;
int cnt = sz(s[0]) - pos - 1;
if (cnt & 1) ans ^= (1 << b);
}
pos = sz(s[1]) - 1;
for (int i = 0; i < sz(s[1]); i++) {
int vl = (1 << b) - s[1][i];
while (pos >= i && s[1][pos] >= vl) pos--;
while (pos < i - 1) pos++;
int cnt = sz(s[1]) - pos - 1;
if (cnt & 1) ans ^= (1 << b);
}
pos = 0;
for (int i = sz(s[1]) - 1; i >= 0; i--) {
int vl = (1 << b) - s[1][i];
while (pos < sz(s[0]) && s[0][pos] < vl) pos++;
if (pos & 1) ans ^= (1 << b);
}
}
cout << ans;
}
main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int tp = 1;
if (flg) cin >> tp;
while (tp--) {
slv();
}
}
//wenomechainsama
Compilation message
xorsum.cpp:84:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
84 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
473 ms |
38964 KB |
Output is correct |
2 |
Correct |
439 ms |
38952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
473 ms |
38964 KB |
Output is correct |
2 |
Correct |
439 ms |
38952 KB |
Output is correct |
3 |
Correct |
579 ms |
40208 KB |
Output is correct |
4 |
Correct |
532 ms |
42400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
70 ms |
5176 KB |
Output is correct |
4 |
Correct |
70 ms |
5320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
473 ms |
38964 KB |
Output is correct |
4 |
Correct |
439 ms |
38952 KB |
Output is correct |
5 |
Correct |
579 ms |
40208 KB |
Output is correct |
6 |
Correct |
532 ms |
42400 KB |
Output is correct |
7 |
Correct |
70 ms |
5176 KB |
Output is correct |
8 |
Correct |
70 ms |
5320 KB |
Output is correct |
9 |
Correct |
718 ms |
47764 KB |
Output is correct |
10 |
Correct |
726 ms |
47916 KB |
Output is correct |
11 |
Correct |
714 ms |
48028 KB |
Output is correct |