Submission #844527

#TimeUsernameProblemLanguageResultExecution timeMemory
844527konberXORanges (eJOI19_xoranges)C++14
100 / 100
116 ms13476 KiB
#include <iostream> #include <vector> using namespace std; vector<int> st1, st2, a; void build(int p, int L, int R){ if(L==R){ if(L%2==0) st1[p] = a[L]; else st2[p] = a[L]; return; } build(2*p, L, (L+R)/2); build(2*p+1, (L+R)/2+1, R); st1[p] = st1[2*p]^st1[2*p+1]; st2[p] = st2[2*p]^st2[2*p+1]; } void update(int p, int L, int R, int pos, int v){ if(L==R){ if(L%2==0) st1[p] = v; else st2[p] = v; return; } int mid=(L+R)/2; if(pos <= mid) update(2*p, L, mid, pos, v); else update(2*p+1, mid+1, R, pos, v); st1[p] = st1[2*p]^st1[2*p+1]; st2[p] = st2[2*p]^st2[2*p+1]; } int rsq1(int p, int L, int R, int i, int j){ if(j < L || i > R) return 0; if(L >= i && R <= j) return st1[p]; int mid=(L+R)/2; return rsq1(2*p, L, mid, i, j)^rsq1(2*p+1, mid+1, R, i, j); } int rsq2(int p, int L, int R, int i, int j){ if(j < L || i > R) return 0; if(L >= i && R <= j) return st2[p]; int mid=(L+R)/2; return rsq2(2*p, L, mid, i, j)^rsq2(2*p+1, mid+1, R, i, j); } int main() { int N, Q; scanf("%d%d", &N, &Q); a.resize(N+1); st1.resize(4*N+1); st2.resize(4*N+1); for(int i=1; i <= N; i++) scanf("%d", &a[i]); build(1, 1, N); while(Q--){ int q, i, j; scanf("%d%d%d", &q, &i, &j); if(q==1){ update(1, 1, N, i, j); } else{ int ans; if((i%2)!=(j%2)) ans=0; else if(i%2==0) ans = rsq1(1, 1, N, i, j); else ans = rsq2(1, 1, N, i, j); printf("%d\n", ans); } } }

Compilation message (stderr)

xoranges.cpp: In function 'int main()':
xoranges.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     scanf("%d%d", &N, &Q);
      |     ~~~~~^~~~~~~~~~~~~~~~
xoranges.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
xoranges.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         scanf("%d%d%d", &q, &i, &j);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...