#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#define I inline void
#define S struct
#define vi vector<int>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 2e6 + 7, mod = 1e9 + 7;
const ll inf = 2e18;
// How interesting!
int n;
int a[N];
ll ans;
int cnts[N];
int bit[N];
void add(int x)
{
++x;
for (; x < N; x += x & -x)
bit[x]++;
}
int get(int x)
{
if (x < 0)
return 0;
++x;
int ret = 0;
for (; x; x -= x & -x)
ret += bit[x];
return ret;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("in.in", "r", stdin);
cin >> n;
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int r = 0; r < 20; ++r)
{
memset(bit, 0, sizeof bit);
int R = (1 << r) * 2;
vector<int> vec;
for (int j = 0; j < n; ++j)
{
add(a[j] % R);
vec.push_back(a[j] % R);
int le = (1 << r), ri = R - 1;
int z = a[j] % R;
if (z <= (1 << r))
{
le -= z;
ri -= z;
int m = get(ri) - get(le - 1);
if (m%2)
ans ^= (1 << r);
}
else
{
int xx = le - z;
int yy = ri - z;
xx = (xx % R + R) % R;
yy = (yy % R + R) % R;
if (xx > yy)
swap(xx, yy);
int m = j + 1 - (get(yy - 1) - get(xx));
if (m%2)
ans ^= (1 << r);
}
}
}
cout << ans;
return 0;
}
/*
- bounds sir (segtree = 4N, eulerTour = 2N, ...)
- a variable defined twice?
- will overflow?
- is it a good complexity?
- don't mess up indices (0-indexed vs 1-indexed)
- reset everything between testcases.
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
8172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1678 ms |
23900 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1678 ms |
23900 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
8172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
8172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |