Submission #465392

#TimeUsernameProblemLanguageResultExecution timeMemory
465392a1415926XORanges (eJOI19_xoranges)C++14
100 / 100
662 ms10516 KiB
#include <iostream> #include <vector> #include <cmath> using namespace std; typedef vector<int> vi; struct segtree { int len; vi a; void make(int n) { len = 1; while (len < n) len *= 2; a.resize(2 * len, 0); } void update(int ind, int val) { ind += len; a[ind] = val; ind /= 2; while (ind > 0) { a[ind] = a[2 * ind + 1] ^ a[2 * ind]; ind /= 2; } } int query(int l, int r) { l += len, r += len; int ans = 0; while (r >= l) { if (l % 2 == 1) ans ^= a[l++]; if (r % 2 == 0) ans ^= a[r--]; l /= 2, r /= 2; } return ans; } }; int main() { int n, q, a_1, type, b_1, b_2; segtree seg1, seg2; cin >> n >> q; seg1.make(n); seg2.make(n); for (int i = 0; i < n; i++) { cin >> a_1; if (i % 2) seg1.update(i, a_1); else seg2.update(i, a_1); } for (int i = 0; i < q; i++) { cin >> type >> b_1 >> b_2; if (type == 1) { if ((b_1-1) % 2) seg1.update(b_1 - 1, b_2); else seg2.update(b_1 - 1, b_2); } if (type == 2) { if ((b_2 - b_1 - 1) % 2) { if ((b_1 - 1) % 2) cout << seg1.query(b_1 - 1, b_2 - 1) << "\n"; else cout << seg2.query(b_1 - 1, b_2 - 1) << "\n"; } else 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...