#include <iostream>
#include <vector>
#include <algorithm>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#define rep(i, s, e) for (ll i = s; i < e; i++)
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vb = vector<bool>;
void solve() {
ll n;
cin >> n;
vll arr(n);
rep(i, 0, n) cin >> arr[i];
ll ans = 0;
rep(b, 0, 28) {
// Look at the first b bits
vll cur0; // Keep all the numbers that have 0 in the b bit with only their first b-1 bits
vll cur1; // Keep all the numbers that have 1 in the b bit with only their first b-1 bits
ll A = ((ll)1 << (b)) - 1;
rep(i, 0, n) {
if ((arr[i] >> b) & (ll)1) cur1.push_back(arr[i] & A);
else cur0.push_back(arr[i] & A);
}
sort(cur0.begin(), cur0.end());
sort(cur1.begin(), cur1.end());
ll res = 0;
ll carry = (ll)1 << b;
rep(i, 0, n) {
ll curVal = arr[i] & A; // The first b-1 bits of arr[i]
ll num0, num1;
if (((2 * arr[i]) >> b) & (ll)1) res++;
if (((arr[i] >> b) & (ll)1) == 0) {
// The b bit is 0
num0 = 0; // The number of numbers that have 0 in the b bit and give carry
num1 = 0; // The number of numbers that have 1 in the b bit and don't give carry
num0 = cur0.end() - lower_bound(cur0.begin(), cur0.end(), carry - curVal);
num1 = lower_bound(cur1.begin(), cur1.end(), carry - curVal) - cur1.begin();
}
else {
// The b bit is 1
num0 = 0; // The number of numbers that have 0 in the b bit and don't give carry
num1 = 0; // The number of numbers that have 1 in the b bit and give carry
num0 = lower_bound(cur0.begin(), cur0.end(), carry - curVal) - cur0.begin();
num1 = cur1.end() - lower_bound(cur1.begin(), cur1.end(), carry - curVal);
}
res += (num0 + num1);
}
res /= 2;
ans += (res % 2) * carry;
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
# | 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... |