Submission #596772

#TimeUsernameProblemLanguageResultExecution timeMemory
596772CookieXORanges (eJOI19_xoranges)C++14
100 / 100
177 ms16116 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define vt vector #define pb push_back const int mxn = 2e5 + 3; ll a[mxn]; int n, q; ll odd[mxn * 4] = {}, even[mxn * 4] = {}; void build(int nd, int l, int r){ if(l == r){ if(l % 2 == 0)even[nd] = a[l]; else odd[nd] = a[l]; return; } int mid = (l + r) >> 1; build((nd << 1), l, mid); build((nd << 1) + 1, mid + 1, r); odd[nd] = odd[(nd << 1)] ^ odd[(nd << 1) + 1]; even[nd] = even[(nd << 1)] ^ even[(nd << 1) + 1]; } void upd(int nd, int l, int r, int id, ll v){ if(id > r || id < l)return; if(l == r){ even[nd] = v; return; } int mid = (l + r) >> 1; upd((nd << 1), l, mid, id, v); upd((nd << 1) + 1, mid + 1, r, id, v); even[nd] = even[(nd << 1)] ^ even[(nd << 1) + 1]; } void upd2(int nd, int l, int r, int id, ll v){ if(id > r || id < l)return; if(l == r){ odd[nd] = v; return; } int mid = (l + r) >> 1; upd2((nd << 1), l, mid, id, v); upd2((nd << 1) + 1, mid + 1, r, id, v); odd[nd] = odd[(nd << 1)] ^ odd[(nd << 1) + 1]; } ll get(int nd, int l, int r, int ql, int qr){ if(ql > r || qr < l)return(0); if(ql <= l && qr >= r)return(even[nd]); int mid = (l + r) >> 1; return(get((nd << 1), l, mid, ql, qr) ^ get((nd << 1) + 1, mid + 1, r, ql,qr)); } ll get2(int nd, int l, int r, int ql, int qr){ if(ql > r || qr < l)return(0); if(ql <= l && qr >= r)return(odd[nd]); int mid = (l + r) >> 1; return(get2((nd << 1), l, mid, ql, qr) ^ get2((nd << 1) + 1, mid + 1, r, ql,qr)); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q; for(int i = 1; i <= n; i++)cin >> a[i]; build(1, 1, n); for(int i = 0; i < q; i++){ int qq; cin >> qq; if(qq == 1){ int id; cin >> id; ll x; cin >> x; if(id % 2 == 0){ upd(1, 1, n, id, x); }else{ upd2(1, 1, n, id, x); } a[id] = x; }else{ int l, r; cin >> l >> r; if((r - l + 1) % 2 == 0)cout << 0 << "\n"; else{ if(l % 2 == 0){ cout << get(1, 1, n, l, r) << "\n"; }else{ cout << get2(1, 1, n, l, r) << "\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...