Submission #286278

#TimeUsernameProblemLanguageResultExecution timeMemory
286278errayXORanges (eJOI19_xoranges)C++17
100 / 100
118 ms6136 KiB
// author: erray #undef DEBUG #include<bits/stdc++.h> using namespace std; template<typename T, typename F> string to_string(pair<T, F> p); template<typename T, typename F, typename Tr> string to_string(tuple<T, F, Tr> p); template<typename T, typename F, typename Tr, typename Th> string to_string(tuple<T, F, Tr, Th> p); string to_string(string s) { return '"' + s + '"'; } string to_string(char c) { return (string) "'" + c + "'"; } string to_string(const char* p) { return to_string((string) p); } string to_string(bool B) { return (B ? "true" : "false"); } string to_string(vector<bool> v) { string res = "{"; for (int i = 0; i < (int) v.size(); ++i) { if ((int) res.size() > 1) res += ", "; res += to_string(v[i]); } res += "}"; return res; } template<size_t T> string to_string(bitset<T> bs) { return bs.to_string(); } template<typename T> string to_string(T v) { string res = "{"; for (auto& el : v) { if ((int) res.size() > 1) res += ", "; res += to_string(el); } res += "}"; return res; } template<typename T, typename F> string to_string(pair<T, F> p) { return '(' + to_string(p.first) + ", " + to_string(p.second) + ')'; } template<typename T, typename F, typename Tr> string to_string(tuple<T, F, Tr> p) { return '(' + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ')'; } template<typename T, typename F, typename Tr, typename Th> string to_string(tuple<T, F, Tr, Th> p) { return '(' + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ')'; } void debug_out() { cerr << endl; } template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef DEBUG #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" , debug_out(__VA_ARGS__) #else #define debug(...) (void) 37 #endif class bit { public: vector<int> tree; int n; bit(int _n) : n(_n) { tree.resize(n + 1); } int get(int ind) { if (ind == -1) return 0; ++ind; int res = 0; while (ind) { res ^= tree[ind]; ind -= ind & -ind; } return res; } int get(int l, int r) { return get(r) ^ get(l - 1); } void modify(int ind, int val) { int old = get(ind, ind); ++ind; while (ind <= n) { tree[ind] ^= old; tree[ind] ^= val; ind += ind & -ind; } } }; int main () { ios_base::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; bit b0(n), b1(n); for (int i = 0; i < n; ++i) { int x; cin >> x; if (i % 2) { b1.modify(i, x); } else b0.modify(i, x); } while (q--) { int t, l, r; cin >> t >> l >> r; if (t == 2) { --l; --r; if ((r - l + 1) % 2 == 0) { cout << 0; } else if (l % 2) { cout << b1.get(l, r); } else { cout << b0.get(l, r); } cout << '\n'; } else { --l; if (l % 2) { b1.modify(l, r); } else { b0.modify(l, r); } } } }
#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...