Submission #425017

#TimeUsernameProblemLanguageResultExecution timeMemory
425017MilosMilutinovicXORanges (eJOI19_xoranges)C++14
100 / 100
209 ms11224 KiB
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; const int M = 4 * N; int a[N], st[M][2]; void build(int node, int l, int r) { if (l > r) return; if (l == r) { st[node][l % 2] = a[l]; return; } int mid = l + r >> 1; build(node * 2, l, mid); build(node * 2 + 1, mid + 1, r); st[node][0] = st[node * 2][0] ^ st[node * 2 + 1][0]; st[node][1] = st[node * 2][1] ^ st[node * 2 + 1][1]; } void update(int node, int l, int r, int pos) { if (l > r) { return; } if (l == r) { st[node][l % 2] = a[l]; return; } int mid = l + r >> 1; if (pos <= mid) update(node * 2, l, mid, pos); else update(node * 2 + 1, mid + 1, r, pos); st[node][0] = st[node * 2][0] ^ st[node * 2 + 1][0]; st[node][1] = st[node * 2][1] ^ st[node * 2 + 1][1]; } int get(int node, int l, int r, int ll, int rr, int p) { if (l > r || l > rr || r < ll) return 0; if (ll <= l && r <= rr) return st[node][p]; int mid = l + r >> 1; return get(node * 2, l, mid, ll, rr, p) ^ get(node * 2 + 1, mid + 1, r, ll, rr, p); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; for (int i = 0; i < n; i++) { cin >> a[i]; } build(1, 0, n - 1); while (q--) { int foo; cin >> foo; if (foo == 1) { int pos, x; cin >> pos >> x; --pos; a[pos] = x; update(1, 0, n - 1, pos); } else { int l, r; cin >> l >> r; --l, --r; if (l % 2 != r % 2) { cout << 0 << '\n'; continue; } cout << get(1, 0, n - 1, l, r, l % 2) << '\n'; } } return 0; }

Compilation message (stderr)

xoranges.cpp: In function 'void build(int, int, int)':
xoranges.cpp:16:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   16 |   int mid = l + r >> 1;
      |             ~~^~~
xoranges.cpp: In function 'void update(int, int, int, int)':
xoranges.cpp:31:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |   int mid = l + r >> 1;
      |             ~~^~~
xoranges.cpp: In function 'int get(int, int, int, int, int, int)':
xoranges.cpp:41:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |   int mid = l + r >> 1;
      |             ~~^~~
#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...