#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
int n;
int a[maxn];
int b[maxn];
bool check(int bit)
{
int result = 0;
int cnt = 0;
vector<int> rems;
for (int i = 1; i <= n; ++i)
{
if ((a[i] & (1 << bit)) != 0)
{
++cnt;
}
rems.push_back((a[i] % (1 << bit)));
}
result = (1LL * result + (1LL * cnt) * (1LL * (n - cnt))) % 2;
sort(rems.begin(), rems.end());
int r = n - 1;
for (int l = 0; l < n; ++l)
{
if (l > r)
{
++r;
}
while (r > l && rems[l] + rems[r - 1] >= (1 << bit))
{
--r;
}
if (rems[l] + rems[r] >= (1 << bit))
{
result = (result + n - r) % 2;
}
}
int ptr1 = 1;
int ptr2 = n - cnt + 1;
for (int i = 1; i <= n; ++i)
{
if ((a[i] & (1 << bit)) != 0)
{
b[ptr2++] = a[i];
}
else
{
b[ptr1++] = a[i];
}
}
for (int i = 1; i <= n; ++i)
{
a[i] = b[i];
}
return result;
}
void fastIO()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
{
fastIO();
cin >> n;
int max_val = 0;
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
max_val = max(max_val, a[i]);
}
int ans = 0;
int up_to = 0;
int curr = 1;
while (curr < max_val)
{
++up_to;
curr *= 2;
}
for (int i = 0; i <= up_to; ++i)
{
if (check(i) == true)
{
ans += (1 << i);
}
}
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
398 ms |
16168 KB |
Output is correct |
2 |
Correct |
407 ms |
15364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
398 ms |
16168 KB |
Output is correct |
2 |
Correct |
407 ms |
15364 KB |
Output is correct |
3 |
Correct |
699 ms |
16152 KB |
Output is correct |
4 |
Correct |
632 ms |
15748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
91 ms |
2016 KB |
Output is correct |
4 |
Correct |
90 ms |
2040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
398 ms |
16168 KB |
Output is correct |
4 |
Correct |
407 ms |
15364 KB |
Output is correct |
5 |
Correct |
699 ms |
16152 KB |
Output is correct |
6 |
Correct |
632 ms |
15748 KB |
Output is correct |
7 |
Correct |
91 ms |
2016 KB |
Output is correct |
8 |
Correct |
90 ms |
2040 KB |
Output is correct |
9 |
Correct |
961 ms |
16160 KB |
Output is correct |
10 |
Correct |
995 ms |
25504 KB |
Output is correct |
11 |
Correct |
955 ms |
25520 KB |
Output is correct |