#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[MaxLog][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++;
}
}
for (int x = 1; x < MaxLog; x++)
{
k = 1;
for (int y = 1; y <= n; y++)
{
if (!((arr[id[x - 1][y]] >> x) & 1))
{
id[x][k] = id[x - 1][y];
k++;
}
}
for (int y = 1; y <= n; y++)
{
if ((arr[id[x - 1][y]] >> x) & 1)
{
id[x][k] = id[x - 1][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[x][y]] + arr2[id[x][z1]] >= a))
{
z1--;
}
cnt -= z1 - y + 1;
z2 = max(z2, y - 1);
while (z2 >= y && (arr2[id[x][y]] + arr2[id[x][z2]] >= b))
{
z2--;
}
cnt += z2 - y + 1;
z3 = max(z3, y - 1);
while (z3 >= y && (arr2[id[x][y]] + arr2[id[x][z3]] >= c))
{
z3--;
}
cnt -= z3 - y + 1;
if (z1 < y && z2 < y && z3 < y)
{
break;
}
}
//cout << cnt << " ";
if (cnt >= 0 && 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 |
8 ms |
41820 KB |
Output is correct |
2 |
Correct |
3 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
628 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
628 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
41820 KB |
Output is correct |
2 |
Correct |
3 ms |
1116 KB |
Output is correct |
3 |
Incorrect |
86 ms |
15184 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
41820 KB |
Output is correct |
2 |
Correct |
3 ms |
1116 KB |
Output is correct |
3 |
Runtime error |
628 ms |
131072 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |