#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<math.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pair<ll, ll>>;
using vvpll = vector<vpll>;
void solve() {
ll n;
cin >> n;
ll arr[(ll)1e6 + 1];
for (ll i = 0; i < n; i++) cin >> arr[i];
ll ans = 0;
for (ll b = 0; b < 30; b++) {
// 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;
for (ll i= 0;i <n; i++) {
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());
long long res = 0;
ll carry = (ll)1 << b;
for (ll i = 0; i < n; i++) {
ll curVal = arr[i] & A; // The first b-1 bits of arr[i]
long long num0 = 0, num1 = 0;
if (((2 * arr[i]) >> b) & (ll)1) res++;
if (((arr[i] >> b) & (ll)1) == 0) {
// The b bit is 0
// num0 = The number of numbers that have 0 in the b bit and give carry
// num1 = 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 = The number of numbers that have 0 in the b bit and don't give carry
// num1 = 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);
cout.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... |