#include<bits/stdc++.h>
#include<math.h>
#define _USE_MATH_DEFINES
using namespace std;
struct seg_tree{
vector<int> seg;
int n;
void build(int l, int r, int ind, vector<int>&a){
if(l == r) {
seg[ind] = a[l];
return;
}
int mid = (l + r) / 2;
build(l, mid, ind*2 + 1, a);
build(mid+1, r, ind*2 + 2, a);
seg[ind] = seg[ind*2 +1] ^ seg[ind*2 + 2];
}
seg_tree(vector<int>& a){
n = a.size();
seg.resize(4*n, 0);
build(0, n-1, 0, a);
}
int query(int l, int r, int ind, int currL, int currR){
if(l >= currL && r <= currR) return seg[ind];
else if(currL > r || currR < l) return 0;
int mid = (l + r) / 2;
return query(l, mid, ind*2 + 1, currL, currR) ^ query(mid+1, r, ind*2 + 2, currL, currR);
}
int query(int currL, int currR){
return query(0, n-1, 0, currL, currR);
}
void update(int l, int r, int ind, int pos, int val){
if(l == r) {
seg[ind] = val;
return;
}
int mid = (l + r)/2;
if(pos <= mid){
update(l, mid, ind*2+1, pos, val);
}
else{
update(mid+1, r, ind*2+2, pos, val);
}
seg[ind] = seg[ind*2 +1] ^ seg[ind*2 + 2];
}
void update(int pos, int val){
update(0, n-1, 0, pos, val);
}
};
int main()
{
int n,m;
cin>>n>>m;
int x[n];
vector<int>a1;
vector<int>a2;
for(int i=0;i<n;i++)
{
cin>>x[i];
if(i%2==0)
{
a1.push_back(x[i]);
a2.push_back(0);
}
else
{
a1.push_back(0);
a2.push_back(x[i]);
}
}
seg_tree st1(a1);
seg_tree st2(a2);
while(m--)
{
int k;
cin>>k;
if(k==1)
{
int idx;
int nval;
cin>>idx>>nval;
idx--;
if(idx%2==0)
st1.update(idx,nval);
else
st2.update(idx,nval);
}
else{
int l,r;
cin>>l>>r;
l--;
r--;
if(l%2==0)
cout<<st1.query(l,r)<<endl;
else
cout<<st2.query(l,r)<<endl;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
489 ms |
11016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |