Submission #675660

#TimeUsernameProblemLanguageResultExecution timeMemory
675660AlmaXORanges (eJOI19_xoranges)C++17
0 / 100
535 ms9008 KiB
#include <bits/stdc++.h> using namespace std; int n, m, q; vector<int> a, values; vector<int> segTree; void build(int x, int l, int r) { if (l == r) { segTree[x] = values[l]; return; } int mid = (l+r)/2; build(2*x, l, mid); build(2*x+1, mid+1, r); segTree[x] = segTree[2*x] ^ segTree[2*x+1]; } void update(int x, int l, int r, int i, int v) { if (l == r) { segTree[x] = values[l] = v; return; } int mid = (l+r)/2; if (i <= mid) { update(2*x, l, mid, i, v); } else{ update(2*x+1, mid+1, r, i, v); } segTree[x] = segTree[2*x] ^ segTree[2*x+1]; } int getRange(int x, int l, int r, int lb, int rb) { if (rb <= l or r <= lb) { return 0; } else if (lb <= l and r <= rb) { return segTree[x]; } else { int mid = (l+r)/2; int xor1 = getRange(2*x, l, mid, lb, rb); int xor2 = getRange(2*x+1, mid+1, r, lb, rb); return xor1 ^ xor2; } } int main() { // ios::sync_with_stdio(false); // cin.tie(NULL); cin >> n >> q; a = vector<int>(n); for (int& i: a) cin >> i; m = (n+1)/2; values = vector<int>(m); for (int i = 0; i < m; i++) { values[i] = a[2*i]; } segTree = vector<int>(4*m, 0); build(1, 0, m-1); // cout << "ok\n"; int type, i, val, l, r; while (q--) { cin >> type; if (type == 1) { // rescan cin >> i >> val; a[i-1] = val; if (i % 2 == 1) { i /= 2; update(1, 0, m-1, i, val); } } else { // query cin >> l >> r; int range = r-l+1; if (l == r) { cout << a[l-1] << '\n'; } else if (range % 2 == 0) { cout << "0\n"; } else { l /= 2; r /= 2; cout << getRange(1, 0, m-1, l, r) << '\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...