Submission #1009469

#TimeUsernameProblemLanguageResultExecution timeMemory
1009469cpismylifeOwOXOR Sum (info1cup17_xorsum)C++17
7 / 100
509 ms23772 KiB
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int MaxN = 1e6 + 5; const int MaxLog = 31; int n; long long arr[MaxN]; void Inp() { cin >> n; for (int x = 1; x <= n; x++) { cin >> arr[x]; } } long long arr2[MaxN]; int id[2][MaxN]; void Exc() { long long res = 0; int k = 1; for (int x = 1; x <= n; x++) { if (arr[x] % 2 == 0) { id[0][k] = x; k++; } arr2[x] = arr[x] & 1; } if ((1ll * (k - 1) * (n - k + 1)) & 1) { res ^= 1ll; } for (int x = 1; x <= n; x++) { if (arr[x] & 1ll) { id[0][k] = x; k++; } } bool avl = true; for (int x = 1; x < MaxLog; x++) { k = 1; for (int y = 1; y <= n; y++) { if (!((arr[id[!avl][y]] >> x) & 1)) { id[avl][k] = id[!avl][y]; k++; } } for (int y = 1; y <= n; y++) { if ((arr[id[!avl][y]] >> x) & 1) { id[avl][k] = id[!avl][y]; k++; } } for (int y = 1; y <= n; y++) { arr2[y] ^= (arr[y] & (1ll << x)); } long long cnt = n * (n + 1) / 2; int z1 = n, z2 = n, z3 = n; long long a = (1ll << x) + (1ll << (x + 1)), b = (1ll << (x + 1)), c = (1ll << x); for (int y = 1; y <= n; y++) { z1 = max(z1, y - 1); while (z1 >= y && (arr2[id[avl][y]] + arr2[id[avl][z1]] >= a)) { z1--; } cnt -= z1 - y + 1; z2 = max(z2, y - 1); while (z2 >= y && (arr2[id[avl][y]] + arr2[id[avl][z2]] >= b)) { z2--; } cnt += z2 - y + 1; z3 = max(z3, y - 1); while (z3 >= y && (arr2[id[avl][y]] + arr2[id[avl][z3]] >= c)) { z3--; } cnt -= z3 - y + 1; if (z1 < y && z2 < y && z3 < y) { break; } } avl = !avl; //cout << cnt << " "; if (cnt >= 0 && cnt & 1) { res ^= (1ll << x); } //cout << cnt << "\n"; } cout << res; } int main() { //freopen("B.INP", "r", stdin); //freopen("B.OUT", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(nullptr); int test = 1; //cin >> test; for (int x = 1; x <= test; x++) { Inp(); Exc(); } 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...