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 int long long
using namespace std;
const int N = 2e5+1;
vector<int> a(N);
void build(int idx, int l, int r, vector<int>& segt, int rest){
if (l == r){
if (l%2 == rest) segt[idx] = a[l];
return;
}
int mid = (l+r)>>1;
build(2*idx,l,mid,segt,rest);
build(2*idx+1,mid+1,r,segt,rest);
segt[idx] = segt[2*idx]^segt[2*idx+1];
}
void modify(int idx, int l, int r, int pos, int val, vector<int>& segt){
if (r < pos or l > pos) return;
if (l == r){
segt[idx] = val;
return;
}
int mid = (l+r)>>1;
modify(2*idx,l,mid,pos,val,segt);
modify(2*idx+1,mid+1,r,pos,val,segt);
segt[idx] = segt[2*idx]^segt[2*idx+1];
}
int query(int idx, int l, int r, int L, int R, vector<int>& segt){
if (r < L or l > R) return 0;
if (l >= L and r <= R) return segt[idx];
int mid = (l+r)>>1;
return query(2*idx,l,mid,L,R,segt)^query(2*idx+1,mid+1,r,L,R,segt);
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,q;
cin >> n >> q;
vector<int> odd(4*N+5), even(4*N+5);
for (int i=0; i<n; ++i){
cin >> a[i];
}
build(1,0,n-1,even,0);
build(1,0,n-1,odd,1);
for (int i=0; i<q; ++i){
int type;
cin >> type;
if (type == 1){
int pos, val;
cin >> pos >> val;
pos--;
if (pos%2 == 0) modify(1,0,n-1,pos,val,even);
else modify(1,0,n-1,pos,val,odd);
}
else{
int l,r;
cin >> l >> r;
l--; r--;
int ans = 0;
if ((r-l+1)%2 == 0){
cout << 0 << '\n';
continue;
if (l%2 == 0) ans = query(1,0,n-1,l,r,odd);
else ans = query(1,0,n-1,l,r,even);
}
else{
if (l%2 == 0) ans = query(1,0,n-1,l,r,even);
else ans = query(1,0,n-1,l,r,odd);
}
cout << ans << '\n';
}
}
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... |