Submission #336649

#TimeUsernameProblemLanguageResultExecution timeMemory
336649NursikXORanges (eJOI19_xoranges)C++14
100 / 100
862 ms11628 KiB
#include <bits/stdc++.h> #define fi first #define se second #define pp pop_back #define ll long long #define pb push_back #define ld long double #define debug cout << "OK\n"; #define all(x) x.begin(), x.end() using namespace std; const int N = 1e6 + 200; const int mod = 1e9 + 7; const int mod2 = 998244353; /* Rucode: jaqVYNrpMj JUDGE_ID: 295965SY */ void data() { #ifdef NURS freopen("main.in", "r", stdin); freopen("main.out", "w", stdout); #endif } void speed_force() { ios_base::sync_with_stdio(0), cin.tie(0),cout.tie(0); } int n, q; int a[N]; struct seg_tree { int t[N * 4]; void upd(int pos, int val, int v = 1, int tl = 1, int tr = n) { if (tl == tr) { t[v] = val; return; } int tm = (tl + tr) / 2; if (pos <= tm) upd(pos, val, v * 2, tl, tm); else upd(pos, val, v * 2 + 1, tm + 1, tr); t[v] = (t[v + v] ^ t[v + v + 1]); } int get(int l, int r, int v = 1, int tl = 1, int tr = n) { if (l <= tl && tr <= r) return t[v]; if (l > tr || r < tl) return 0; int tm = (tl + tr) / 2; return (get(l, r, v * 2, tl, tm) ^ (get(l, r, v * 2 + 1, tm + 1, tr))); } } tree[4]; main() { data(); cin >> n >> q; for (int i = 1; i <= n; i++) { tree[0].upd(i, 0); tree[1].upd(i, 0); } for (int i = 1; i <= n; i++) { cin >> a[i]; if (i & 1) tree[1].upd(i, a[i]); else tree[0].upd(i, a[i]); } for (int i = 1; i <= q; i++) { int type; cin >> type; if (type == 2) { int l, r; cin >> l >> r; if ((r - l + 1) % 2 == 0) { cout << 0; } else { if (l % 2) { cout << tree[1].get(l, r); } else { cout << tree[0].get(l, r); } } cout << '\n'; } else { int pos, x; cin >> pos >> x; if (pos & 1) tree[1].upd(pos, x); else tree[0].upd(pos, x); } } } /* n = 6 (1, 2, 3, 4, 5, 6, 7) 1 0 1 0 1 0 1 */

Compilation message (stderr)

xoranges.cpp:65:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main()
      |      ^
#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...