# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
681382 | iosif_andrei_ | XOR Sum (info1cup17_xorsum) | C++14 | 1051 ms | 37636 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int v[1000001], X[1000001], n, POW[32], szX, szY, low[1000001], high[1000001];
int* vp, * xp;
bool bit;
struct poz {
int val, i;
}a[1000002], x[1000001], y[1000001];
bitset <1000001> b;
int main()
{
cin >> n;
int maxi = 0;
for (int i = 0; i <= 30; i++)
POW[i] = (1 << i);
for (int i = 1; i <= n; i++)
{
cin >> v[i];
maxi = max(maxi, v[i]);
}
int l, r, m, poz1, poz2, poz;
int res = 0, downLim, upLim, aux, sz, i;
for (int i = 1; i <= n; i++)
a[i].i = i, a[i].val = 0;
for (int k = 0; k <= 29; k++)
{
bit = false;
vp = v;
vp++;
xp = X;
xp++;
szX = szY = 0;
for (i = 1; i <= n; i++)
{
if (*vp & 1)
*xp += POW[k], b[i] = true;
else
b[i] = false;
*vp >>= 1;
vp++;
xp++;
}
for (i = 1; i <= n; i++)
if (b[a[i].i])
a[i].val += POW[k], y[++szY] = a[i];
else
x[++szX] = a[i];
for (i = 1; i <= szX; i++)
a[i] = x[i];
for (int i = 1; i <= szY; i++)
a[szX + i] = y[i];
aux = (1 << k) + (1 << (k + 1));
downLim = POW[k];
upLim = POW[k + 1] - 1;
l = 1, r = 1;
while (r <= n && a[l].val + a[r].val < aux)
r++;
if (r == n + 1)
{
while (l <= n && a[l].val + a[n].val < aux)
l++;
r = n;
}
if (l != n + 1 && r != n + 1)
{
while (l < r)
{
while (l < r && a[l].val + a[r - 1].val >= aux)
r--;
bit ^= (n - r + 1) & 1;
l++;
}
while (l <= n)
bit ^= (n - (l++) + 1) & 1;
}
int last = n;
for (int i = 1; i <= n; i++)
{
if (a[i].val + a[n].val < downLim)
{
low[i] = 0;
continue;
}
while (last > 1 && a[i].val + a[last - 1].val >= downLim)
last--;
if (last < i)
low[i] = i;
else
low[i] = last;
}
l = 1, r = n;
while (l <= r && a[l].val + a[r].val > upLim)
r--;
while (l <= r)
{
high[l] = r;
l++;
while (l <= r && a[l].val + a[r].val > upLim)
r--;
}
while (l <= n)
high[l++] = 0;
for (i = 1; i <= n; i++)
if (low[i] && high[i] && low[i] <= high[i])
bit ^= (high[i] - low[i] + 1) & 1;
if (bit)
res += POW[k];
}
cout << res;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |