# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
720356 | GrandTiger1729 | XOR Sum (info1cup17_xorsum) | C++17 | 822 ms | 51752 KiB |
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>
using namespace std;
const int N = 30;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
int ans = 0;
if (n % 2 == 0){
for (int j = 0; j < N; j++){
int cnt = 0;
for (int i = 0; i < n; i++){
if (a[i] & 1 << j)
cnt++;
}
ans ^= (cnt & 1) << j;
}
}
vector<pair<int, int>> res(n);
for (int i = 0; i < n; i++)
res[i] = make_pair(a[i] & 1, i);
sort(res.begin(), res.end());
auto calc = [&](int j) -> long long {
int r = n;
long long ret = 0;
for (int i = 0; i < n; i++){
while (r > 0 && res[r - 1].first >= (1 << j + 1) - res[i].first) r--;
ret += n - r;
ret += res[i].first >= (1 << j);
}
return ret;
};
long long cnt = calc(0) / 2;
ans ^= (cnt & 1) << 1;
for (int j = 1; j < N; j++){
vector<pair<int, int>> b, c;
for (int i = 0; i < n; i++){
if (a[res[i].second] & 1 << j)
c.push_back(make_pair(res[i].first ^ 1 << j, res[i].second));
else
b.push_back(res[i]);
}
b.insert(b.end(), c.begin(), c.end());
swap(res, b);
cnt = calc(j) / 2;
ans ^= (cnt & 1) << j + 1;
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
# | 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... |