Submission #823883

#TimeUsernameProblemLanguageResultExecution timeMemory
823883borisAngelovXOR Sum (info1cup17_xorsum)C++17
100 / 100
995 ms25520 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1000005; int n; int a[maxn]; int b[maxn]; bool check(int bit) { int result = 0; int cnt = 0; vector<int> rems; for (int i = 1; i <= n; ++i) { if ((a[i] & (1 << bit)) != 0) { ++cnt; } rems.push_back((a[i] % (1 << bit))); } result = (1LL * result + (1LL * cnt) * (1LL * (n - cnt))) % 2; sort(rems.begin(), rems.end()); int r = n - 1; for (int l = 0; l < n; ++l) { if (l > r) { ++r; } while (r > l && rems[l] + rems[r - 1] >= (1 << bit)) { --r; } if (rems[l] + rems[r] >= (1 << bit)) { result = (result + n - r) % 2; } } int ptr1 = 1; int ptr2 = n - cnt + 1; for (int i = 1; i <= n; ++i) { if ((a[i] & (1 << bit)) != 0) { b[ptr2++] = a[i]; } else { b[ptr1++] = a[i]; } } for (int i = 1; i <= n; ++i) { a[i] = b[i]; } return result; } void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); cin >> n; int max_val = 0; for (int i = 1; i <= n; ++i) { cin >> a[i]; max_val = max(max_val, a[i]); } int ans = 0; int up_to = 0; int curr = 1; while (curr < max_val) { ++up_to; curr *= 2; } for (int i = 0; i <= up_to; ++i) { if (check(i) == true) { ans += (1 << i); } } cout << ans << endl; 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...