Submission #773689

#TimeUsernameProblemLanguageResultExecution timeMemory
773689serifefedartarXORanges (eJOI19_xoranges)C++17
100 / 100
305 ms11224 KiB
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); typedef long long ll; #define mod 1000000007 #define MAXN 200005 vector<int> arr; pair<int,int> sg[4*MAXN]; void init(int k, int a, int b) { if (a == b) { if (a % 2 == 0) sg[k] = {arr[a], 0}; else sg[k] = {0, arr[a]}; return ; } init(2*k, a, (a+b)/2); init(2*k+1, (a+b)/2+1, b); sg[k] = {sg[2*k].first ^ sg[2*k+1].first, sg[2*k].second ^ sg[2*k+1].second}; } void point_update(int k, int a, int b, int plc, int val) { if (plc > b || plc < a) return ; if (a == b) { if (a % 2 == 0) sg[k] = {val, 0}; else sg[k] = {0, val}; return ; } point_update(2*k, a, (a+b)/2, plc, val); point_update(2*k+1, (a+b)/2+1, b, plc, val); sg[k] = {sg[2*k].first ^ sg[2*k+1].first, sg[2*k].second ^ sg[2*k+1].second}; } pair<int,int> query(int k, int a, int b, int q_l, int q_r) { if (q_r < a || q_l > b) return {0, 0}; if (q_l <= a && b <= q_r) return sg[k]; pair<int,int> p1 = query(2*k, a, (a+b)/2, q_l, q_r); pair<int,int> p2 = query(2*k+1, (a+b)/2+1, b, q_l, q_r); return {p1.first ^ p2.first, p1.second ^ p2.second}; } int main() { fast int n, q; cin >> n >> q; arr = vector<int>(n+1); for (int i = 1; i <= n; i++) cin >> arr[i]; init(1, 1, n); while (q--) { int t, i, j; cin >> t >> i >> j; if (t == 1) { point_update(1, 1, n, i, j); } else { if ((j - i + 1) % 2 == 0) cout << 0 << endl; else { if (i % 2 == 0) cout << query(1, 1, n, i, j).first << endl; else cout << query(1, 1, n, i, j).second << endl; } } } }
#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...