#include<bits/stdc++.h>
using namespace std;
const int mxN = 2e5 + 5;
int n;
int a[mxN][2];
int seg[mxN * 2][2];
void build(int l , int r , int node , int t){
if(l==r){
seg[node][t] = a[l][t];
return ;
}
int mid = (l + r) / 2;
build(l , mid , node*2 , t);
build(mid+1 , r , node*2 + 1 , t);
seg[node][t] = seg[node*2][t] ^ seg[node*2 + 1][t];
}
void update(int l , int r, int idx, int node , int val , int t){
if(l>idx || r<idx) return ;
if(l == r){
a[idx][t] = val;
seg[node][t] = val;
return ;
}
int mid = (l+r)/2;
update(l,mid,idx,node*2,val,t);
update(mid+1,r,idx,node*2 + 1 ,val,t);
seg[node][t] = seg[node*2][t] ^ seg[node*2 + 1][t];
}
int query(int l,int r,int curr_l,int curr_r,int node,int t){
if(curr_l>r || curr_r<l) return 0;
if(l<=curr_l && curr_r<=r) return seg[node][t];
int mid = (curr_l + curr_r) / 2;
return query(l,r,curr_l,mid,node*2,t) ^ query(l,r,mid+1,curr_r,node*2 + 1,t);
}
void display(){
cout<< "\ndisplay\n";
cout<< 1 << "\n";
for(int i=1;i<=n;i++) cout<< a[i][1] << " ";
cout<< "\n";
for(int i=1;i<=2*n;i++) cout<< seg[i][1] << " ";
cout<< "\n2\n";
for(int i=1;i<=n;i++) cout<< a[i][0] << " ";
cout<< "\n";
for(int i=1;i<=2*n;i++) cout<< seg[i][0] << " ";
cout<< "\n";
}
int main(){
ios::sync_with_stdio(0),cin.tie(0);
int q;
cin>> n >> q;
for(int i=1;i<=n;i++) cin>> a[i][i&1];
build(1 , n , 1 , 1);
build(1 , n , 1 , 0);
// cout<< "before \n";
// display();
while(q--){
int cmd;
cin>> cmd;
if(cmd == 1){
int idx , val;
cin>> idx >> val;
update(1,n,idx,1,val,idx&1);
// display();
}else{
int l,r;
cin>> l >> r;
int len = r-l+1;
// cout<< "ans = ";
if(len%2 == 0){
cout<< 0 << '\n';
continue;
}
if(len & 1) cout<< query(l,r,1,n,1,l&1) << "\n";
else cout<< query(l,r,1,n,1,l&1) << "\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2508 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2508 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
3 ms |
2652 KB |
Output is correct |
12 |
Correct |
3 ms |
2652 KB |
Output is correct |
13 |
Correct |
3 ms |
2652 KB |
Output is correct |
14 |
Correct |
3 ms |
2524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
6144 KB |
Output is correct |
2 |
Correct |
103 ms |
11032 KB |
Output is correct |
3 |
Correct |
96 ms |
11060 KB |
Output is correct |
4 |
Correct |
95 ms |
10876 KB |
Output is correct |
5 |
Correct |
87 ms |
10596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2508 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
3 ms |
2652 KB |
Output is correct |
12 |
Correct |
3 ms |
2652 KB |
Output is correct |
13 |
Correct |
3 ms |
2652 KB |
Output is correct |
14 |
Correct |
3 ms |
2524 KB |
Output is correct |
15 |
Correct |
100 ms |
6144 KB |
Output is correct |
16 |
Correct |
103 ms |
11032 KB |
Output is correct |
17 |
Correct |
96 ms |
11060 KB |
Output is correct |
18 |
Correct |
95 ms |
10876 KB |
Output is correct |
19 |
Correct |
87 ms |
10596 KB |
Output is correct |
20 |
Incorrect |
98 ms |
10800 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |