#include <bits/stdc++.h>
using namespace std;
struct segtree{
int n;
vector<int> v,l,r;
segtree(int na){
n=1<<int(ceil(log2(na)));
v.resize(2*n);
l.resize(2*n);
r.resize(2*n);
for(int i=0; i<n; i++) l[i+n]=r[i+n]=i;
for(int i=n-1; i>0; i--){
l[i]=l[2*i];
r[i]=r[2*i+1];
}
}
void set(int i, int val){
i+=n;
v[i]=val;
i/=2;
while(i){
v[i]=v[2*i]^v[2*i+1];
i/=2;
}
}
int query(int left, int right, int u=1){
if(left>r[u] || right < l[u]) return 0;
if(left<=l[u] && right >=r[u]) return v[u];
return query(left,right,2*u)^query(left,right,2*u+1);
}
};
int main(){
int n,q;
cin>>n>>q;
segtree even(n), odd(n);
for(int i=0; i<n; i++){
int t;
cin>>t;
if(i%2==0) even.set(i,t);
else odd.set(i,t);
}
for(int i=0; i<q; i++){
int t;
cin>>t;
if(t==1){
int x,y;
cin>>x>>y;
x--;
if(x%2==0) even.set(x,y);
else odd.set(x,y);
}
else{
int l,u;
cin>>l>>u;
l--;u--;
if((u-l+1)%2==0){
cout<<0<<endl;
continue;
}
if(l%2==0) cout<<even.query(l,u)<<endl;
else cout<<odd.query(l,u)<<endl;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
288 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
304 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
288 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
304 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
2 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
296 KB |
Output is correct |
11 |
Correct |
13 ms |
716 KB |
Output is correct |
12 |
Correct |
13 ms |
716 KB |
Output is correct |
13 |
Correct |
19 ms |
716 KB |
Output is correct |
14 |
Correct |
19 ms |
788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
774 ms |
18564 KB |
Output is correct |
2 |
Correct |
740 ms |
18704 KB |
Output is correct |
3 |
Correct |
736 ms |
18620 KB |
Output is correct |
4 |
Correct |
650 ms |
18288 KB |
Output is correct |
5 |
Correct |
667 ms |
18232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
288 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
304 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
2 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
296 KB |
Output is correct |
11 |
Correct |
13 ms |
716 KB |
Output is correct |
12 |
Correct |
13 ms |
716 KB |
Output is correct |
13 |
Correct |
19 ms |
716 KB |
Output is correct |
14 |
Correct |
19 ms |
788 KB |
Output is correct |
15 |
Correct |
774 ms |
18564 KB |
Output is correct |
16 |
Correct |
740 ms |
18704 KB |
Output is correct |
17 |
Correct |
736 ms |
18620 KB |
Output is correct |
18 |
Correct |
650 ms |
18288 KB |
Output is correct |
19 |
Correct |
667 ms |
18232 KB |
Output is correct |
20 |
Correct |
551 ms |
18456 KB |
Output is correct |
21 |
Correct |
559 ms |
18372 KB |
Output is correct |
22 |
Correct |
556 ms |
18468 KB |
Output is correct |
23 |
Correct |
679 ms |
18288 KB |
Output is correct |
24 |
Correct |
670 ms |
18372 KB |
Output is correct |