#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize("O3")
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <map>
#include <iomanip>
#include <numeric>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <random>
#include <queue>
#include <cstring>
#define sz(a) (int)((a).size())
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using ld = long double;
using pll = pair<ll, ll>;
const int N = 1e6 + 228;
const int LG = 30;
int n;
int a[N];
ll cnt_bit[LG];
int cnt[2];
int new_a[N];
vi z, o;
void upd(int bit, int x) {
cnt_bit[bit] += x;
}
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
z.reserve(n);
o.reserve(n);
for (int bit = 0; bit < LG; bit++) {
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < n; i++) {
cnt[a[i] >> bit & 1]++;
}
cnt[1] += cnt[0];
for (int i = n - 1; i >= 0; i--) {
new_a[--cnt[a[i] >> bit & 1]] = a[i];
}
memcpy(a, new_a, sizeof(a));
z.clear();
o.clear();
for (int i = 0; i < n; i++) {
if (a[i] >> bit & 1) {
o.pb(a[i] & ((1 << bit) - 1));
}
else {
z.pb(a[i] & ((1 << bit) - 1));
}
}
int pz = 0, po = 0;
for (int i = sz(z) - 1; i >= 0; i--) {
int x = z[i];
while (pz < sz(z) && x + z[pz] < (1 << bit)) {
pz++;
}
while (po < sz(o) && x + o[po] < (1 << bit)) {
po++;
}
upd(bit, sz(z) - pz + (pz < sz(z) && z[pz] <= x));
upd(bit, po);
}
pz = po = 0;
for (int i = sz(o) - 1; i >= 0; i--) {
int x = o[i];
while (pz < sz(z) && x + z[pz] < (1 << bit)) {
pz++;
}
while (po < sz(o) && x + o[po] < (1 << bit)) {
po++;
}
upd(bit, pz);
upd(bit, sz(o) - po + (po < sz(o) && o[po] <= x));
}
}
int ans = 0;
for (int i = 0; i < LG; i++) {
if ((cnt_bit[i] >> 1) & 1) {
ans ^= (1 << i);
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
4344 KB |
Output is correct |
2 |
Correct |
21 ms |
4344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
642 ms |
14968 KB |
Output is correct |
2 |
Correct |
590 ms |
18680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
642 ms |
14968 KB |
Output is correct |
2 |
Correct |
590 ms |
18680 KB |
Output is correct |
3 |
Correct |
747 ms |
21784 KB |
Output is correct |
4 |
Correct |
719 ms |
21212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
4344 KB |
Output is correct |
2 |
Correct |
21 ms |
4344 KB |
Output is correct |
3 |
Correct |
116 ms |
6264 KB |
Output is correct |
4 |
Correct |
116 ms |
6264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
4344 KB |
Output is correct |
2 |
Correct |
21 ms |
4344 KB |
Output is correct |
3 |
Correct |
642 ms |
14968 KB |
Output is correct |
4 |
Correct |
590 ms |
18680 KB |
Output is correct |
5 |
Correct |
747 ms |
21784 KB |
Output is correct |
6 |
Correct |
719 ms |
21212 KB |
Output is correct |
7 |
Correct |
116 ms |
6264 KB |
Output is correct |
8 |
Correct |
116 ms |
6264 KB |
Output is correct |
9 |
Correct |
941 ms |
24316 KB |
Output is correct |
10 |
Correct |
943 ms |
24380 KB |
Output is correct |
11 |
Correct |
956 ms |
24472 KB |
Output is correct |