This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define endl "\n"
#define int long long
#define see(x) cerr<<#x<<"="<<x<<endl;
using namespace std;
const int N = 2*1e5 + 10;
int n, q, a[N], t1[4*N], t2[4*N];
void build (int x, int l, int r) {
if (l == r) {
if (l % 2) t1[x] = a[l];
else t2[x] = a[l];
return;
}
int m = (l + r) / 2;
build(2*x+1, l, m);
build(2*x+2, m+1, r);
t1[x] = t1[2*x+1] ^ t1[2*x+2];
t2[x] = t2[2*x+1] ^ t2[2*x+2];
}
void update (int x, int l, int r, int i, int v) {
if (l == r) {
if (i % 2) t1[x] = v;
else t2[x] = v;
return;
}
int m = (l + r) / 2;
if (i > m) update(2*x+2, m+1, r, i, v);
else update(2*x+1, l, m, i, v);
t1[x] = t1[2*x+1] ^ t1[2*x+2];
t2[x] = t2[2*x+1] ^ t2[2*x+2];
}
int get (int x, int lx, int rx, int l, int r, int type) {
if (lx > r or rx < l) return 0;
if (lx >= l and rx <= r) {
if (type == 1) return t1[x];
else return t2[x];
}
int m = (lx + rx) / 2;
int g1 = get(2*x+1, lx, m, l, r, type);
int g2 = get(2*x+2, m+1, rx, l, r, type);
return g1 ^ g2;
}
int32_t main () {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> q;
for (int i = 0; i < n; ++ i)
cin >> a[i];
build(0, 0, n-1);
while (q --) {
int t, i, j;
cin >> t >> i >> j;
if (t == 1) update(0, 0, n-1, i-1, j);
else if ((j - i) % 2) cout << "0\n";
else if (i % 2) cout << get(0, 0, n-1, i-1, j-1, 2) << endl;
else cout << get(0, 0, n-1, i-1, j-1, 1) << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |