Submission #682680

#TimeUsernameProblemLanguageResultExecution timeMemory
682680typ_ikXOR Sum (info1cup17_xorsum)C++17
100 / 100
461 ms21388 KiB
#include <bits/stdc++.h> #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define watch(x) cout << (#x) << " : " << x << '\n' using namespace std; const int LOG = 30; void solve() { int n; cin >> n; vector <int> a(n); for (auto& x : a) cin >> x; vector <int> cnt(LOG, 0); for (auto& x : a) for (int b = 0; b < LOG; b++) cnt[b] += (x >> b) & 1; int ans = 0; for (int b = 0; b < LOG; b++) { auto replace = [&]() -> void { int pt = n - cnt[b], l = 0; vector <int> c(n); for (int i = 0; i < n; i++) if ((a[i] >> b) & 1) c[pt++] = a[i]; else c[l++] = a[i]; swap(a, c); }; int pairs = 0; if (cnt[b] * (n - cnt[b]) & 1) pairs++; int msk = (1 << b) - 1; vector <int> c(n); for (int i = 0; i < n; i++) c[i] = a[i] & msk; replace(); int r = n; for (int l = 0; l < n; l++) { while (r - 1 >= l && c[r - 1] + c[l] >= (1 << b)) r--; pairs += (n - max(l, r)); pairs &= 1; } ans ^= (pairs << b); } cout << ans << '\n'; } int32_t main() { boost; solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...