#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int MaxN = 1e6 + 5;
const int MaxLog = 30;
int n;
int arr[MaxN];
void Inp()
{
cin >> n;
for (int x = 1; x <= n; x++)
{
cin >> arr[x];
}
}
int 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] & 1)
{
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
6488 KB |
Output is correct |
2 |
Correct |
4 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
435 ms |
18648 KB |
Output is correct |
2 |
Correct |
395 ms |
18000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
435 ms |
18648 KB |
Output is correct |
2 |
Correct |
395 ms |
18000 KB |
Output is correct |
3 |
Correct |
562 ms |
19596 KB |
Output is correct |
4 |
Correct |
507 ms |
19288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
6488 KB |
Output is correct |
2 |
Correct |
4 ms |
6492 KB |
Output is correct |
3 |
Correct |
73 ms |
11612 KB |
Output is correct |
4 |
Correct |
73 ms |
11612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
6488 KB |
Output is correct |
2 |
Correct |
4 ms |
6492 KB |
Output is correct |
3 |
Correct |
435 ms |
18648 KB |
Output is correct |
4 |
Correct |
395 ms |
18000 KB |
Output is correct |
5 |
Correct |
562 ms |
19596 KB |
Output is correct |
6 |
Correct |
507 ms |
19288 KB |
Output is correct |
7 |
Correct |
73 ms |
11612 KB |
Output is correct |
8 |
Correct |
73 ms |
11612 KB |
Output is correct |
9 |
Correct |
786 ms |
20952 KB |
Output is correct |
10 |
Correct |
748 ms |
20808 KB |
Output is correct |
11 |
Correct |
741 ms |
20952 KB |
Output is correct |