Submission #391502

#TimeUsernameProblemLanguageResultExecution timeMemory
391502warner1129XOR Sum (info1cup17_xorsum)C++17
100 / 100
548 ms20420 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int arr[maxn], n; int A[maxn], B[maxn], p1, p2; int check() { int ret = 0; for (int i = 1; i <= n; i++) for (int j = i; j <= n; j++) ret ^= arr[i] + arr[j]; return ret; } void solve() { cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i]; int ans = 0; for (int i = 0; i < 30; i++) { int R = (1<<i) - 1; p1 = p2 = 0; for (int j = 1; j <= n; j++) if ((arr[j]>>i)&1) B[++p2] = arr[j]; else A[++p1] = arr[j]; int ptr = p1 + 1; for (int j = 1; j <= p1; j++) { while (ptr > j && (A[j]&R) + (A[ptr-1]&R) >= (1<<i)) ptr--; if (ptr < j) ptr = j; if ((p1-ptr+1)&1) ans ^= (1<<i); } ptr = p2 + 1; for (int j = 1; j <= p2; j++) { while (ptr > j && (B[j]&R) + (B[ptr-1]&R) >= (1<<i)) ptr--; if (ptr < j) ptr = j; if ((p2-ptr+1)&1) ans ^= (1<<i); } ptr = p2; for (int j = 1; j <= p1; j++) { while (ptr && (A[j]&R)+(B[ptr]&R) >= (1<<i)) ptr--; if (ptr&1) ans ^= (1<<i); } for (int j = 1; j <= p1; j++) arr[j] = A[j]; for (int j = 1; j <= p2; j++) arr[p1 + j] = B[j]; } cout << ans << '\n'; } signed main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); 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...