Submission #844900

#TimeUsernameProblemLanguageResultExecution timeMemory
844900fanwenXORanges (eJOI19_xoranges)C++17
100 / 100
329 ms13264 KiB
#include <bits/stdc++.h> using namespace std; #define MASK(x) (1LL << (x)) #define BIT(x, i) (((x) >> (i)) & 1) #define ALL(x) (x).begin(), (x).end() #define REP(i, n) for (int i = 0, _n = n; i < _n; ++i) #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) #define FORE(i, a, b) for (int i = (a), _b = (b); i < _b; ++i) #define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } template <class A, class B> bool minimize(A &a, B b) { if (a > b) { a = b; return true; } return false; } template <class A, class B> bool maximize(A &a, B b) { if (a < b) { a = b; return true; } return false; } template < class T, T (*f) (T, T), T (*e) ()> struct segment_tree { vector <T> tree; int n; void update(int u, T p) { u--; for(tree[u += n] += p; u >>= 1; ) { tree[u] = f(tree[u << 1], tree[u << 1 | 1]); } } void set(int u, T p) { u--; for (tree[u += n] = p; u >>= 1; ) { tree[u] = f(tree[u << 1], tree[u << 1 | 1]); } } T get(int p) { return tree[p += n - 1]; } T get(int l, int r) { l--; T resl = e(), resr = e(); for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if(l & 1) resl = f(resl, tree[l++]); if(r & 1) resr = f(tree[--r], resr); } return f(resl, resr); } segment_tree(int n = 0) : n(n), tree(n << 2 | 1) { fill(tree.begin(), tree.end(), 0); } }; int merge(int x, int y) { return x ^ y; } int e() { return 0; } void you_make_it(void) { int n, q; cin >> n >> q; vector <int> a(n + 1); segment_tree <int, merge, e> it0(n), it1(n); FOR(i, 1, n) { cin >> a[i]; (i & 1 ? it1 : it0).set(i, a[i]); } while(q--) { int op, l, r; cin >> op >> l >> r; if(op == 1) { (l & 1 ? it1 : it0).set(l, r); } else if(r - l & 1) cout << 0 << endl; else cout << (r & 1 ? it1 : it0).get(l, r) << endl; } } signed main() { #ifdef LOCAL freopen("TASK.inp", "r", stdin); freopen("TASK.out", "w", stdout); #endif auto start_time = chrono::steady_clock::now(); cin.tie(0), cout.tie(0) -> sync_with_stdio(0); you_make_it(); auto end_time = chrono::steady_clock::now(); cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl; return (0 ^ 0); } // Dream it. Wish it. Do it.

Compilation message (stderr)

xoranges.cpp: In function 'void you_make_it()':
xoranges.cpp:71:21: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   71 |         } else if(r - l & 1) cout << 0 << endl;
      |                   ~~^~~
xoranges.cpp: In instantiation of 'segment_tree<T, f, e>::segment_tree(int) [with T = int; T (* f)(T, T) = merge; T (* e)() = e]':
xoranges.cpp:62:39:   required from here
xoranges.cpp:21:9: warning: 'segment_tree<int, merge, e>::n' will be initialized after [-Wreorder]
   21 |     int n;
      |         ^
xoranges.cpp:20:16: warning:   'std::vector<int> segment_tree<int, merge, e>::tree' [-Wreorder]
   20 |     vector <T> tree;
      |                ^~~~
xoranges.cpp:51:5: warning:   when initialized here [-Wreorder]
   51 |     segment_tree(int n = 0) : n(n), tree(n << 2 | 1) {
      |     ^~~~~~~~~~~~
#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...