Submission #748601

#TimeUsernameProblemLanguageResultExecution timeMemory
748601Desh03XORanges (eJOI19_xoranges)C++17
100 / 100
122 ms8692 KiB
#include <bits/stdc++.h> using namespace std; struct fenwick { vector<int> fenw; int n; fenwick(int n_) : n(n_) { fenw.resize(n); } void upd(int u, int x) { for (; u < n; u |= u + 1) fenw[u] ^= x; } int qry(int u) { int xr = 0; for (; u >= 0; u = (u & (u + 1)) - 1) xr ^= fenw[u]; return xr; } int qry(int l, int r) { return qry(r) ^ qry(l - 1); } }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector<int> a(n); fenwick bit1(n), bit2(n); for (int i = 0; i < n; i++) { cin >> a[i]; if (i & 1) bit2.upd(i, a[i]); else bit1.upd(i, a[i]); } while (q--) { int t, l, u; cin >> t >> l >> u; if (t == 1) { --l; if (l & 1) bit2.upd(l, u ^ a[l]); else bit1.upd(l, u ^ a[l]); a[l] = u; } else { --l, --u; if (u - l & 1) cout << "0\n"; else cout << (l & 1 ? bit2.qry(l, u) : bit1.qry(l, u)) << '\n'; } } }

Compilation message (stderr)

xoranges.cpp: In function 'int main()':
xoranges.cpp:45:19: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   45 |             if (u - l & 1) cout << "0\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...