#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
using namespace std;
const int bulan = 23;
int n,a[1000005],v[1000005],vmax;
int fp[(1 << (bulan + 1)) + 1000];
int branza_topita;
int order[1000005],neworder[1000005];
int f(int x)
{
if (branza_topita <= bulan)
return fp[x];
int st = 0,pas = 1 << 19;
while (pas != 0)
{
if (st + pas <= n and v[st + pas] < x)
st += pas;
pas >>= 1;
}
return st + 1;
}
void sorteaza()
{
vector<int>apoi;
int idx = 0;
for (int i = 1; i <= n; i++)
{
if ((a[order[i]] & (1 << branza_topita)) == 0)
neworder[++idx] = order[i];
else
apoi.push_back(order[i]);
}
for (auto it : apoi)
neworder[++idx] = it;
for (int i = 1; i <= n; i++)
order[i] = neworder[i];
for (int i = 1; i <= n; i++)
v[i] = a[order[i]] & ((1 << (branza_topita + 1)) - 1);
}
void prec()
{
if (branza_topita > bulan)
return;
v[n + 1] = (1 << (branza_topita + 1));
v[0] = 0;
fp[0] = 1;
for (int i = 1; i <= n + 1; i++)
{
for (int j = v[i - 1] + 1; j <= v[i]; j++)
fp[j] = i;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
vmax = max(vmax,a[i]);
}
for (int i = 1; i <= n; i++)
order[i] = i;
int ans = 0;
for (int b = 0; (1 << b) <= 2 * vmax; b++)
{
branza_topita = b;
//for (int i = 1; i <= n; i++)
// v[i] = a[order[i]] & ((1 << (b + 1)) - 1);
sorteaza();
prec();
int cate = 0;
for (int i = 1; i <= n; i++)
{
if ((v[i] & (1 << b)) == 0)
{
///v[j] >= 2^b - v[i] si v[j] < 2^(b+1) - v[i], in plus j <= i
int l = f((1 << b) - v[i]),r = f((1 << (b + 1)) - v[i]) - 1;
if (l <= i and (min(i,r) - l + 1) % 2 == 1)
cate ^= 1;
}
else
{
///v[j] < 2^(b+1) - v[i] sau v[j] >= 3 * 2^b - v[i]
int r1 = f((1 << (b + 1)) - v[i]) - 1,l2 = f(3 * (1 << b) - v[i]);
if (r1 % 2 == 1)
cate ^= 1;
if (l2 <= i and (i - l2 + 1) % 2 == 1)
cate ^= 1;
}
}
if (cate == 1)
ans += (1 << b);
if (branza_topita <= bulan)
{
for (int i = 0; i <= (1 << (branza_topita + 1)); i++)
fp[i] = 0;
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
71760 KB |
Output is correct |
2 |
Correct |
40 ms |
71768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
216 ms |
20524 KB |
Output is correct |
2 |
Correct |
190 ms |
20244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
216 ms |
20524 KB |
Output is correct |
2 |
Correct |
190 ms |
20244 KB |
Output is correct |
3 |
Correct |
350 ms |
28732 KB |
Output is correct |
4 |
Correct |
351 ms |
28656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
71760 KB |
Output is correct |
2 |
Correct |
40 ms |
71768 KB |
Output is correct |
3 |
Correct |
144 ms |
76700 KB |
Output is correct |
4 |
Correct |
144 ms |
76784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
71760 KB |
Output is correct |
2 |
Correct |
40 ms |
71768 KB |
Output is correct |
3 |
Correct |
216 ms |
20524 KB |
Output is correct |
4 |
Correct |
190 ms |
20244 KB |
Output is correct |
5 |
Correct |
350 ms |
28732 KB |
Output is correct |
6 |
Correct |
351 ms |
28656 KB |
Output is correct |
7 |
Correct |
144 ms |
76700 KB |
Output is correct |
8 |
Correct |
144 ms |
76784 KB |
Output is correct |
9 |
Correct |
1590 ms |
85776 KB |
Output is correct |
10 |
Correct |
1566 ms |
94652 KB |
Output is correct |
11 |
Correct |
1520 ms |
94476 KB |
Output is correct |