Submission #634044

#TimeUsernameProblemLanguageResultExecution timeMemory
634044antimirageXORanges (eJOI19_xoranges)C++14
100 / 100
640 ms11188 KiB
#include <iostream> #include <algorithm> #include <vector> #include <math.h> #include <set> #include <map> using namespace std; const int N = 2e5 + 5; int n, q, a[N], type, l, r, t[2][N * 4]; void build (int v = 1, int tl = 1, int tr = n) { if (tl == tr) { t[tl & 1][v] = a[tl]; } else { int tm = (tl + tr) >> 1; build(v + v, tl, tm); build(v + v + 1, tm + 1, tr); t[0][v] = t[0][v + v] ^ t[0][v + v + 1]; t[1][v] = t[1][v + v] ^ t[1][v + v + 1]; } } void update (int pos, int val, int v = 1, int tl = 1, int tr = n) { if (tl == tr) { t[tl & 1][v] = val; } else { int tm = (tl + tr) >> 1; if (pos <= tm) update(pos, val, v + v, tl, tm); else update(pos, val, v + v + 1, tm + 1, tr); t[0][v] = t[0][v + v] ^ t[0][v + v + 1]; t[1][v] = t[1][v + v] ^ t[1][v + v + 1]; } } int get (int l, int r, int v = 1, int tl = 1, int tr = n) { if (l > tr || tl > r) return 0; if (l <= tl && tr <= r) return t[l & 1][v]; int tm = (tl + tr) >> 1; return get(l, r, v + v, tl, tm) ^ get(l, r, v + v + 1, tm + 1, tr); } main(){ cin >> n >> q; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } build(); while (q--) { cin >> type >> l >> r; if (type == 1) { update(l, r); } else { if ((r - l + 1) & 1) { printf("%d\n", get(l, r)); } else { puts("0"); } } } }

Compilation message (stderr)

xoranges.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   50 | main(){
      | ^~~~
xoranges.cpp: In function 'int main()':
xoranges.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
#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...