Submission #389411

#TimeUsernameProblemLanguageResultExecution timeMemory
389411cheissmartXOR Sum (info1cup17_xorsum)C++14
45 / 100
1658 ms39500 KiB
#include <bits/stdc++.h> #define F first #define S second #define V vector #define PB push_back #define EB emplace_back #define MP make_pair #define ALL(v) (v).begin(), (v).end() #define debug(x) cerr << "LINE(" << __LINE__ << "): " << #x << " is " << x << endl using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; const int INF = 1e9 + 7, N = 1e5 + 1; struct trie { int t[N * 30][2], sz[N * 30]; int hb, cnt; trie(int _hb) { hb = _hb; memset(t, 0, sizeof t); memset(sz, 0, sizeof sz); cnt = 0; } void add(int x) { int u = 0; for(int i = hb; i >= 0; i--) { int c = x >> i & 1; if(t[u][c] == 0) t[u][c] = ++cnt; u = t[u][c]; sz[u]++; } } int carry(int u, int x, int bit) { if(u == 0 || bit < 0) return 0; int ans = 0; if(x >> bit & 1) { ans += sz[t[u][1]]; ans += carry(t[u][0], x, bit - 1); } else { ans += carry(t[u][1], x, bit - 1); } return ans; } int qry(int x) { int c = x >> hb & 1; int ans = 0; for(int i = 0; i < 2; i++) { if(t[0][i] == 0) continue; int res = c ^ i; if(res == 0) ans += carry(t[0][i], x, hb - 1); else ans += sz[t[0][i]] - carry(t[0][i], x, hb - 1); } return ans; } }; signed main() { ios::sync_with_stdio(0), cin.tie(0); mt19937 rng(time(0)); int n; cin >> n; //n = 10; vi a(n); for(int i = 0; i < n; i++) { cin >> a[i]; //a[i] = rng() % 100; } /*int myans = 0; for(int i = 0; i < n; i++) for(int j = i; j < n; j++) myans ^= a[i] + a[j]; debug(myans); */ int ans = 0; for(int bit = 0; bit < 30; bit++) { ll odd_cnt = 0; trie t(bit); for(int i = 0; i < n; i++) { t.add(a[i]); odd_cnt += t.qry(a[i]); } //debug(odd_cnt); if(odd_cnt & 1) ans |= 1 << bit; } cout << ans << '\n'; }
#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...