Submission #929333

#TimeUsernameProblemLanguageResultExecution timeMemory
929333hngrXORanges (eJOI19_xoranges)C++14
100 / 100
471 ms16208 KiB
//UDUUUU SHAAGD LLR CN INGEL DAWCIH YMN DEER SONIN PSDA WE; #include <iostream> #include <vector> #include <set> #include <cstdio> #include <cmath> #include <algorithm> #include <string> #define int long long using namespace std; const int N = 2e5+7; 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 qry1(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 qry1(2*node+1, l, mid, L, R)^qry1(2*node+2, mid+1, r, L, R); } } int qry2(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 qry2(2*node+1, l, mid, L, R)^qry2(2*node+2, mid+1, r, L, R); } } int32_t main(){ 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 a, b; cin >> a >> b; a--; Update(0, 0, n-1, a, b); } else{ int l, r; cin >> l >> r; r--; l--; int len=r-l+1; if(len&1){ if(l&1){ cout << qry2(0, 0, n-1, l, r) << '\n'; } else { cout << qry1(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...