Submission #735093

#TimeUsernameProblemLanguageResultExecution timeMemory
735093makravXORanges (eJOI19_xoranges)C++14
100 / 100
150 ms18148 KiB
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vei; typedef vector<vei> vevei; #define coa \ for (auto i : a) { \ cout << i << ' '; \ } \ cout << '\n'; #define cia \ for (auto& i : a) { \ cin >> a; \ } #define cna \ int n; \ cin >> n; \ vector<int> a(n); \ for (int i = 0; i < n; i++) { \ cin >> a[i]; \ } #define cnka \ int n, k; \ cin >> n >> k; \ vector<int> a(n); \ for (int i = 0; i < n; i++) { \ cin >> a[i]; \ } #define cnab \ int n; \ cin >> n; \ vector<int> a(n); \ for (int i = 0; i < n; i++) { \ cin >> a[i]; \ } \ vector<int> b(n); \ for (int i = 0; i < n; i++) { \ cin >> b[i]; \ } #define all(a) (a).begin(), (a).end() #define sz(a) (int) a.size() #define con cout << "NO\n" #define coe cout << "YES\n"; #define str string #define pb push_back #define ff first #define sc second #define pii pair<int, int> #define mxe max_element #define mne min_element #define stf shrink_to_fit #define f(i, l, r) for (int i = (l); i < (r); i++) #define double ld #define int long long struct segtree { int n; vector<int> a; vector<int> t; segtree() = default; segtree(int n_, vector<int> a_) { n = n_; a = a_; t.assign(4 * n, 0); build(1, 0, n); } void build(int v, int tl, int tr) { if (tl + 1 == tr) { t[v] = a[tl]; return; } int tm = (tl + tr) / 2; build(v * 2, tl, tm); build(v * 2 + 1, tm, tr); t[v] = (t[v * 2] ^ t[v * 2 + 1]); } void upd(int v, int tl, int tr, int pos, int val) { if (tl + 1 == tr) { t[v] = val; return; } int tm = (tl + tr) / 2; if (pos < tm) upd(v * 2, tl, tm, pos, val); else upd(v * 2 + 1, tm, tr, pos, val); t[v] = (t[v * 2] ^ t[v * 2 + 1]); } int req(int v, int tl, int tr, int l, int r) { if (l <= tl && tr <= r) return t[v]; if (tr <= l || tl >= r) return 0; int tm = (tl + tr) / 2; return (req(v * 2, tl, tm, l, r) ^ req(v * 2 + 1, tm, tr, l, r)); } }; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, q; cin >> n >> q; vector<int> a(n); for (auto& u : a) cin >> u; vector<int> ch, nch; f(i, 0, n) { if (i % 2 == 0) ch.pb(a[i]); else nch.pb(a[i]); } segtree sg0(sz(ch), ch), sg1(sz(nch), nch); while (q--) { int t; cin >> t; if (t == 1) { int p, v; cin >> p >> v; p--; if (p % 2 == 0) { sg0.upd(1, 0, sz(ch), p / 2, v); } else { sg1.upd(1, 0, sz(nch), p / 2, v); } } else { int l, r; cin >> l >> r; l--; r--; if ((r - l + 1) % 2 == 0) { cout << "0\n"; } else { if (l % 2 == 0) { cout << sg0.req(1, 0, sz(ch), l / 2, r / 2 + 1) << '\n'; } else { cout << sg1.req(1, 0, sz(nch), l / 2, r / 2 + 1) << '\n'; } } } } return 0; }
#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...