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>
using namespace std;
#define ar array
const int N = 2e5 + 1;
int n;
struct SegTree{
vector <ar<int,2>> T;
SegTree(){ T.resize(N * 4, {0, 0}); }
void upd(int v, int l, int r, int p, int x){
if ( l == r ){
T[v][0] = x;
return;
}
int m = (l + r) / 2;
if ( m >= p ) upd(v * 2, l, m, p, x);
else upd(v * 2 + 1, m + 1, r, p, x);
int b = (m - l + 1) & 1;
T[v][0] = T[v * 2][0] ^ T[v * 2 + 1][b];
T[v][1] = T[v * 2][1] ^ T[v * 2 + 1][b ^ 1];
}
void upd(int p, int x){ upd(1, 0, n - 1, p, x); }
int get(int v, int l, int r, int tl, int tr, int k){
if ( l > tr || r < tl ) return 0;
if ( tl <= l && tr >= r ) return T[v][k];
int m = (l + r) / 2;
int b = max(0, m - tl + 1) & 1;
return get(v * 2, l, m, tl, tr, k) ^ get(v * 2 + 1, m + 1, r, tl, tr, k ^ b);
}
int qry(int l, int r){
if ( (r - l) & 1 ) return 0;
return get(1, 0, n - 1, l, r, 0);
}
} seg;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int q; cin >> n >> q;
for ( int i = 0; i < n; i++ ){
int x; cin >> x;
seg.upd(i, x);
}
while ( q-- ){
int t, l, u; cin >> t >> l >> u;
if ( t == 1 ){
seg.upd(l - 1, u);
} else cout << seg.qry(l - 1, u - 1) << '\n';
}
cout << '\n';
}
# | 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... |