제출 #810714

#제출 시각아이디문제언어결과실행 시간메모리
810714AlphaMale06XORanges (eJOI19_xoranges)C++14
100 / 100
108 ms11204 KiB
#include <bits/stdc++.h> using namespace std; const int N = 200010; int a[N]; int st1[4*N]; int st2[4*N]; void Build(int node, int l, int r){ if(l>r)return; if(l==r){ if(l&1){ st2[node]=a[l]; } else{ st1[node]=a[l]; } return; } int mid=(l+r)/2; Build(2*node+1, l, mid); Build(2*node+2, mid+1, r); st1[node]=st1[2*node+1]^st1[2*node+2]; st2[node]=st2[2*node+1]^st2[2*node+2]; } void Update(int node, int l, int r, int ind, int val){ if(l>r || l>ind || r<ind)return; if(l==r){ if(l&1){ st2[node]=val; } else st1[node]=val; return; } else{ int mid=(l+r)/2; Update(2*node+1, l, mid, ind, val); Update(2*node+2, mid+1, r, ind, val); } st2[node]=st2[2*node+1]^st2[2*node+2]; st1[node]=st1[2*node+1]^st1[2*node+2]; } int get1(int node, int l, int r, int L, int R){ if(l>R || r<L || l>r){ return 0; } else if(l>=L && r<=R){ return st1[node]; } else{ int mid=(l+r)/2; return get1(2*node+1, l, mid, L, R)^get1(2*node+2, mid+1, r, L, R); } } int get2(int node, int l, int r, int L, int R){ if(l>R || r<L || l>r){ return 0; } else if(l>=L && r<=R){ return st2[node]; } else{ int mid=(l+r)/2; return get2(2*node+1, l, mid, L, R)^get2(2*node+2, mid+1, r, L, R); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q; for(int i=0; i< n; i++){ cin >> a[i]; } Build(0, 0, n-1); while(q--){ int t; cin >> t; if(t==1){ int ind, val; cin >> ind >> val; ind--; Update(0, 0, n-1, ind, val); } else{ int l, r; cin >> l >> r; r--; l--; int len=r-l+1; if(len&1){ if(l&1){ cout << get2(0, 0, n-1, l, r) << '\n'; } else { cout << get1(0, 0, n-1, l, r) << '\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...