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
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 2e5+10;
const int mod = 1e9+7;
const int inf = 1e18;
int a[N];
struct fenwick {
vector<int>fenw;
void build(int n) {
fenw.resize(n+1);
}
void update(int index,int n,int val) {
while(index <= n) {
fenw[index] ^= val;
index += index & -index;
}
}
int get(int x) {
int ret = 0;
while(x >= 1) {
ret ^= fenw[x];
x -= x & -x;
}
return ret;
}
};
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,Q;
cin >> n >> Q;
fenwick ft[2];
ft[0].build(n);
ft[1].build(n);
for(int i=1;i<=n;i++) {
cin >> a[i];
ft[i & 1].update(i,n,a[i]);
}
//cout << ft[1].get(n) << ' ' << ft[0].get(n) << endl;
while(Q--) {
int type;
cin >> type;
if(type & 1) {
int index,val;
cin >> index >> val;
ft[index & 1].update(index,n,a[index]);
a[index] = val;
ft[index & 1].update(index,n,a[index]);
}
else {
int l,r;
cin >> l >> r;
if((r-l+1) % 2 == 0) {
cout << 0 << endl;
continue;
}
if(l == r) {
cout << a[l] << endl;
continue;
}
cout << (ft[(r-l+1) & 1].get(r) ^ ft[(r-l+1) & 1].get(l-1)) << '\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... |