Submission #1135319

#TimeUsernameProblemLanguageResultExecution timeMemory
1135319Dragos1XORanges (eJOI19_xoranges)C++20
0 / 100
364 ms14748 KiB
#include <iostream> #include <vector> using namespace std; int t,n,c,l,r,poz,x,vechi,ans; struct nod1{ int val; int mesaj; }; vector<nod1> aint_impare,aint_pare; void build_pare(int nod,int st,int dr) { if(st==dr) { return; } else{ int mij=(st+dr)/2; build_pare(2*nod,st,mij); build_pare(2*nod+1,mij+1,dr); aint_pare[nod].val=aint_pare[2*nod].val^aint_pare[2*nod+1].val; aint_pare[nod].mesaj=0; } } void build_impare(int nod,int st,int dr) { if(st==dr) { cin>>aint_impare[nod].val; if(st%2==0) aint_pare[nod].val=aint_impare[nod].val , aint_impare[nod].val=0; else{ aint_pare[nod].val=0; } aint_impare[nod].mesaj=0; aint_pare[nod].mesaj=0; } else{ int mij=(st+dr)/2; build_impare(2*nod,st,mij); build_impare(2*nod+1,mij+1,dr); aint_impare[nod].val=aint_impare[2*nod].val^aint_impare[2*nod+1].val; aint_impare[nod].mesaj=0; } } void query_impare(int nod,int st,int dr, int a,int b) { if(a<=st && dr<=b) { ans^=(aint_impare[nod].val); } else{ int mij=(st+dr)/2; if(a<=mij) query_impare(2*nod,st,mij,a,b); if(b>mij) query_impare(2*nod+1,mij+1,dr,a,b); aint_impare[nod].val=aint_impare[2*nod].val^aint_impare[2*nod+1].val; } } void query_pare(int nod,int st,int dr, int a,int b) { if(a<=st && dr<=b) { ans^=(aint_pare[nod].val); } else{ int mij=(st+dr)/2; if(a<=mij) query_pare(2*nod,st,mij,a,b); if(b>mij) query_pare(2*nod+1,mij+1,dr,a,b); aint_pare[nod].val=aint_pare[2*nod].val^aint_pare[2*nod+1].val; } } void update_pare(int nod,int st,int dr,int poz,int x) { if(st==dr) { vechi=aint_pare[nod].val; aint_pare[nod].val^=vechi; aint_pare[nod].val^=x; } else{ int mij=(st+dr)/2; if(poz<=mij) update_pare(2*nod,st,mij,poz,x); else update_pare(2*nod+1,mij+1,dr,poz,x); aint_pare[nod].val^=vechi; aint_pare[nod].val^=x; } } void update_impare(int nod,int st,int dr,int poz,int x) { if(st==dr) { vechi=aint_impare[nod].val; aint_impare[nod].val^=vechi; aint_impare[nod].val^=x; } else{ int mij=(st+dr)/2; if(poz<=mij) update_impare(2*nod,st,mij,poz,x); else update_impare(2*nod+1,mij+1,dr,poz,x); aint_impare[nod].val^=vechi; aint_impare[nod].val^=x; } } int main() { cin>>n>>t; aint_impare.resize(4*n+10); aint_pare.resize(4*n+10); build_impare(1,1,n); build_pare(1,1,n); while(t--) { cin>>c; if(c==1) { cin>>poz>>x; vechi=0; if(poz%2) update_impare(1,1,n,poz,x); else update_pare(1,1,n,poz,x); } else{ cin>>l>>r; ans=0; if(l%2) query_impare(1,1,n,l,r); else query_pare(1,1,n,l,r); cout<<ans<<'\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...