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>
#define int unsigned
#define task " "
using namespace std;
const int maxn = 1e6 + 1, mod = 1e9 + 7;
int n, a[maxn], m[maxn], id[maxn], cnt = 0, idx = 0, res = 0, t, p, r;
vector<int> v[2];
signed main ()
{
//freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
m[i] = 0;
id[i] = i;
}
m[n + 1] = (1U << 31);
for (int j = 0; j <= 29; j++)
{
cnt = idx = 0; v[0].clear(); v[1].clear();
for (int i = 1; i <= n; i++)
v[(a[id[i]] >> j) & 1].push_back(id[i]);
for (int i : v[0])
{
m[++idx] = a[i] & ((1U << (j + 1)) - 1);
id[idx] = i;
}
for (int i : v[1])
{
m[++idx] = a[i] & ((1U << (j + 1)) - 1);
id[idx] = i;
}
t = p = r = n + 1;
for (int i = 1; i <= n; i++)
{
while (t > 1 && m[t - 1] >= (1U << (j + 1)) - m[i]) t--;
while (p > 1 && m[p - 1] >= (1U << j) - m[i]) p--;
while (r > 1 && m[r - 1] >= (1U << j) + (1U << (j + 1)) - m[i]) r--;
cnt += (min(t, i + 1) - min(p, i + 1)) + (i + 1 - min(r, i + 1));
//cnt += lower_bound(m + 1, m + i + 1, (1LL << (j + 1)) - m[i]) - lower_bound(m + 1, m + i + 1, (1LL << j) - m[i]);
//cnt += lower_bound(m + 1, m + i + 1, (1LL << (j + 2)) - m[i]) - lower_bound(m + 1, m + i + 1, (1LL << j) + (1LL << (j + 1)) - m[i]);
}
res += (cnt & 1)*(1 << j);
}
cout << res;
}
# | 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... |