#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int MaxN = 1e6 + 5;
const int MaxLog = 31;
int n;
long long arr[MaxN];
void Inp()
{
cin >> n;
for (int x = 1; x <= n; x++)
{
cin >> arr[x];
}
}
long long arr2[MaxN];
int id[2][MaxN];
void Exc()
{
long long res = 0;
int k = 1;
for (int x = 1; x <= n; x++)
{
if (arr[x] % 2 == 0)
{
id[0][k] = x;
k++;
}
arr2[x] = arr[x] & 1;
}
if ((1ll * (k - 1) * (n - k + 1)) & 1)
{
res ^= 1ll;
}
for (int x = 1; x <= n; x++)
{
if (arr[x] & 1ll)
{
id[0][k] = x;
k++;
}
}
bool avl = true;
for (int x = 1; x < MaxLog; x++)
{
k = 1;
for (int y = 1; y <= n; y++)
{
if (!((arr[id[!avl][y]] >> x) & 1))
{
id[avl][k] = id[!avl][y];
k++;
}
}
for (int y = 1; y <= n; y++)
{
if ((arr[id[!avl][y]] >> x) & 1)
{
id[avl][k] = id[!avl][y];
k++;
}
}
for (int y = 1; y <= n; y++)
{
arr2[y] ^= (arr[y] & (1ll << x));
}
long long cnt = n * (n + 1) / 2;
int z1 = n, z2 = n, z3 = n;
long long a = (1ll << x) + (1ll << (x + 1)), b = (1ll << (x + 1)), c = (1ll << x);
for (int y = 1; y <= n; y++)
{
z1 = max(z1, y - 1);
while (z1 >= y && (arr2[id[avl][y]] + arr2[id[avl][z1]] >= a))
{
z1--;
}
cnt -= z1 - y + 1;
}
for (int y = 1; y <= n; y++)
{
z2 = max(z2, y - 1);
while (z2 >= y && (arr2[id[avl][y]] + arr2[id[avl][z2]] >= b))
{
z2--;
}
cnt += z2 - y + 1;
}
for (int y = 1; y <= n; y++)
{
z3 = max(z3, y - 1);
while (z3 >= y && (arr2[id[avl][y]] + arr2[id[avl][z3]] >= c))
{
z3--;
}
cnt -= z3 - y + 1;
}
avl = !avl;
//cout << cnt << " ";
if (cnt & 1)
{
res ^= (1ll << x);
}
//cout << cnt << "\n";
}
cout << res;
}
int main()
{
//freopen("B.INP", "r", stdin);
//freopen("B.OUT", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int test = 1;
//cin >> test;
for (int x = 1; x <= test; x++)
{
Inp();
Exc();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6492 KB |
Output is correct |
2 |
Correct |
4 ms |
6612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
469 ms |
23920 KB |
Output is correct |
2 |
Correct |
417 ms |
23392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
469 ms |
23920 KB |
Output is correct |
2 |
Correct |
417 ms |
23392 KB |
Output is correct |
3 |
Correct |
613 ms |
23888 KB |
Output is correct |
4 |
Correct |
585 ms |
23636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6492 KB |
Output is correct |
2 |
Correct |
4 ms |
6612 KB |
Output is correct |
3 |
Correct |
79 ms |
12892 KB |
Output is correct |
4 |
Correct |
78 ms |
12952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6492 KB |
Output is correct |
2 |
Correct |
4 ms |
6612 KB |
Output is correct |
3 |
Correct |
469 ms |
23920 KB |
Output is correct |
4 |
Correct |
417 ms |
23392 KB |
Output is correct |
5 |
Correct |
613 ms |
23888 KB |
Output is correct |
6 |
Correct |
585 ms |
23636 KB |
Output is correct |
7 |
Correct |
79 ms |
12892 KB |
Output is correct |
8 |
Correct |
78 ms |
12952 KB |
Output is correct |
9 |
Correct |
843 ms |
23768 KB |
Output is correct |
10 |
Correct |
808 ms |
23888 KB |
Output is correct |
11 |
Correct |
763 ms |
23920 KB |
Output is correct |