Submission #202258

#TimeUsernameProblemLanguageResultExecution timeMemory
202258Bagritsevich_StepanXOR Sum (info1cup17_xorsum)C++14
45 / 100
1616 ms22048 KiB
//#include "/Users/stdc++.h" #include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define pii pair < int, int > #define fs first #define sc second #define getfiles ifstream cin("input.txt"); ofstream cout("output.txt"); #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() typedef long long ll; typedef long double ld; const int INF = 2e9; const ll BIG_INF = 1e18; const ll MOD = 1e9 + 7; const int maxn = 1e6 + 5; int n, a[maxn], inds[maxn], bit; vector < int > for_sort[2]; bool get_bit(int x, int k) { return x & (1 << k); } void Sort() { for (int i = 0; i < n; i++) { int ind = inds[i]; for_sort[get_bit(a[ind], bit)].pb(ind); } int ind = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j < sz(for_sort[i]); j++) inds[ind++] = for_sort[i][j]; for_sort[i].clear(); } } int get_val(int i, int j) { int x = a[inds[i]] % (1 << (bit + 1)); int y = a[inds[j]] % (1 << (bit + 1)); return x + y; } void upd_p(int &p, int i, int add) { if (p < i) p = i; while (i < p && get_val(i, p - 1) >= add * (1 << bit)) p--; } int main() { fast_io cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; inds[i] = i; } int ans = 0; for (bit = 0; bit < 30; bit++) { Sort(); int p1 = n, p2 = n, p3 = n; for (int i = 0; i < n; i++) { upd_p(p1, i, 1); upd_p(p2, i, 2); upd_p(p3, i, 3); int cnt_ones = p2 - p1 + n - p3; if (cnt_ones % 2) ans ^= (1 << bit); } } cout << ans << "\n"; 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...