#include<bits/stdc++.h>
#define ll long long
#define task " "
using namespace std;
const int maxn = 1e6 + 1, mod = 1e9 + 7;
ll n, a[maxn], m[maxn], id[maxn], cnt = 0, idx = 0, res = 0;
int t, p, q, r;
vector<int> v[2];
int 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] = (1LL << 32);
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] & ((1LL << (j + 1)) - 1);
id[idx] = i;
}
for (int i : v[1])
{
m[++idx] = a[i] & ((1LL << (j + 1)) - 1);
id[idx] = i;
}
t = p = q = r = n + 1;
for (int i = 1; i <= n; i++)
{
while (t > 1 && m[t - 1] >= (1LL << (j + 1)) - m[i]) t--;
while (p > 1 && m[p - 1] >= (1LL << j) - m[i]) p--;
while (q > 1 && m[q - 1] >= (1LL << (j + 2)) - m[i]) q--;
while (r > 1 && m[r - 1] >= (1LL << j) + (1LL << (j + 1)) - m[i]) r--;
cnt += (min(t, i + 1) - min(p, i + 1)) + (min(q, 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4440 KB |
Output is correct |
2 |
Correct |
3 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
323 ms |
35548 KB |
Output is correct |
2 |
Correct |
302 ms |
34028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
323 ms |
35548 KB |
Output is correct |
2 |
Correct |
302 ms |
34028 KB |
Output is correct |
3 |
Correct |
368 ms |
35728 KB |
Output is correct |
4 |
Correct |
367 ms |
32836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4440 KB |
Output is correct |
2 |
Correct |
3 ms |
4444 KB |
Output is correct |
3 |
Correct |
56 ms |
9808 KB |
Output is correct |
4 |
Correct |
54 ms |
9920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4440 KB |
Output is correct |
2 |
Correct |
3 ms |
4444 KB |
Output is correct |
3 |
Correct |
323 ms |
35548 KB |
Output is correct |
4 |
Correct |
302 ms |
34028 KB |
Output is correct |
5 |
Correct |
368 ms |
35728 KB |
Output is correct |
6 |
Correct |
367 ms |
32836 KB |
Output is correct |
7 |
Correct |
56 ms |
9808 KB |
Output is correct |
8 |
Correct |
54 ms |
9920 KB |
Output is correct |
9 |
Correct |
534 ms |
34696 KB |
Output is correct |
10 |
Correct |
558 ms |
33148 KB |
Output is correct |
11 |
Correct |
579 ms |
35904 KB |
Output is correct |