Submission #1006373

#TimeUsernameProblemLanguageResultExecution timeMemory
1006373JoksimKaktusXORanges (eJOI19_xoranges)C++17
100 / 100
90 ms11968 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; vector <int> seg1(200000*3); vector <int> seg2(200000*3); vector <int> v(200000); void build(int l,int r,int u){ if(l == r){ if(l % 2 == 1){ return; } seg1[u] = v[l]; return; } build(l,(l+r)/2,u*2); build((l+r)/2+1,r,u*2+1); seg1[u] = seg1[u*2]^seg1[u*2+1]; } void update(int l,int r,int u,int v,int k){ if(l == r && l == v){ seg1[u] = k; return; } if(v < l || v > r)return; update(l,(l+r)/2,u*2,v,k); update((l+r)/2+1,r,u*2+1,v,k); seg1[u] = seg1[u*2]^seg1[u*2+1]; } int find(int l,int r,int u,int a,int b,int res){ if(a <= l && b >= r){ return seg1[u]^res; } if(l > b || r < a){ return res; } res = find(l,(l+r)/2,u*2,a,b,res); res = find((l+r)/2+1,r,u*2+1,a,b,res); return res; } void build2(int l,int r,int u){ if(l == r){ if(l % 2 == 0){ return; } seg2[u] = v[l]; return; } build2(l,(l+r)/2,u*2); build2((l+r)/2+1,r,u*2+1); seg2[u] = seg2[u*2]^seg2[u*2+1]; } void update2(int l,int r,int u,int v,int k){ if(l == r && l == v){ seg2[u] = k; return; } if(v < l || v > r)return; update2(l,(l+r)/2,u*2,v,k); update2((l+r)/2+1,r,u*2+1,v,k); seg2[u] = seg2[u*2]^seg2[u*2+1]; } int find2(int l,int r,int u,int a,int b,int res){ if(a <= l && b >= r){ return seg2[u]^res; } if(l > b || r < a){ return res; } res = find2(l,(l+r)/2,u*2,a,b,res); res = find2((l+r)/2+1,r,u*2+1,a,b,res); return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); int n,q; cin >> n >> q; for(int i = 0;i < n;i++){ cin >> v[i]; } build(0,n-1,1); build2(0,n-1,1); while(q--){ /* for(int i = 0;i < 20;i++){ cout << seg1[i] << " "; } cout << "\n"; for(int i = 0;i < 20;i++){ cout << seg2[i] << " "; } */ //cout << "\n"; int x,l,r; cin >> x >> l >> r; if(x == 1){ l--; if(l % 2 == 0){ update(0,n-1,1,l,r); }else{ update2(0,n-1,1,l,r); } }else{ l--; r--; if((r-l) % 2 == 1){ cout << "0\n"; }else{ if(l%2 == 0){ cout << find(0,n-1,1,l,r,0) << "\n"; }else{ cout << find2(0,n-1,1,l,r,0) << "\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...