#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pb push_back
#define pf push_front
#define pi pair<int,int>
const int MAX = 2e5+1;
ll odd[MAX*4], even[MAX*4];
ll arr[MAX];
void build_odd(int v, int l, int r){
if(l==r){
if(l%2==1){
odd[v] =arr[l];
}
return;
}
int m =(l+r)/2;
build_odd(v*2,l,m);
build_odd(v*2+1,m+1,r);
odd[v] = odd[v*2]^odd[v*2+1];
}
void build_even(int v, int l, int r){
if(l==r){
if(l%2==0){
even[v] =arr[l];
}
return;
}
int m =(l+r)/2;
build_even(v*2,l,m);
build_even(v*2+1,m+1,r);
even[v] = even[v*2]^even[v*2+1];
}
void update_even(int v, int l, int r, int pos , int val){
if(l==r){
even[v] = val;
return;
}
int m = (l+r)/2;
if(pos<=m) update_even(v*2,l,m,pos,val);
else update_even(v*2+1,m+1,r,pos,val);
even[v]= even[v*2]^even[v*2+1];
}
void update_odd(int v, int l, int r, int pos , int val){
if(l==r){
odd[v] = val;
return;
}
int m = (l+r)/2;
if(pos<=m) update_odd(v*2,l,m,pos,val);
else update_odd(v*2+1,m+1,r,pos,val);
odd[v]= odd[v*2]^odd[v*2+1];
}
ll get_odd(int v, int l, int r, int fl, int fr){
if(fl>fr) return 0;
else if(l==fl && r==fr) return odd[v];
int m = (l+r)/2;
ll a= get_odd(v*2,l,m,fl,min(fr,m));
ll b = get_odd(v*2+1,m+1,r,max(fl,m+1),fr);
return a^b;
}
ll get_even(int v, int l, int r, int fl, int fr){
if(fl>fr) return 0;
else if(l==fl && r==fr) return even[v];
int m = (l+r)/2;
ll a= get_even(v*2,l,m,fl,min(fr,m));
ll b = get_even(v*2+1,m+1,r,max(fl,m+1),fr);
return a^b;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,q;
cin >> n >> q;
for(int i = 1; i <= n; i++){
cin >> arr[i];
}
build_odd(1,1,n);
build_even(1,1,n);
int type,a,b;
while(q--){
cin >> type >> a >> b;
if(type==2){
if((b-a+1)%2==0){
cout << 0 << endl;
}
else if(a%2==1) cout << get_odd(1,1,n,a,b)<< endl;
else cout<< get_even(1,1,n,a,b)<<endl;
}
else{
if(a%2==1) update_odd(1,1,n,a,b);
else update_even(1,1,n,a,b);
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4564 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4564 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
5 ms |
4440 KB |
Output is correct |
12 |
Correct |
5 ms |
4444 KB |
Output is correct |
13 |
Correct |
13 ms |
4604 KB |
Output is correct |
14 |
Correct |
7 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
297 ms |
13904 KB |
Output is correct |
2 |
Correct |
279 ms |
14092 KB |
Output is correct |
3 |
Correct |
287 ms |
13912 KB |
Output is correct |
4 |
Correct |
291 ms |
13988 KB |
Output is correct |
5 |
Correct |
291 ms |
13904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4564 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
5 ms |
4440 KB |
Output is correct |
12 |
Correct |
5 ms |
4444 KB |
Output is correct |
13 |
Correct |
13 ms |
4604 KB |
Output is correct |
14 |
Correct |
7 ms |
4444 KB |
Output is correct |
15 |
Correct |
297 ms |
13904 KB |
Output is correct |
16 |
Correct |
279 ms |
14092 KB |
Output is correct |
17 |
Correct |
287 ms |
13912 KB |
Output is correct |
18 |
Correct |
291 ms |
13988 KB |
Output is correct |
19 |
Correct |
291 ms |
13904 KB |
Output is correct |
20 |
Correct |
189 ms |
13396 KB |
Output is correct |
21 |
Correct |
177 ms |
13648 KB |
Output is correct |
22 |
Correct |
182 ms |
13464 KB |
Output is correct |
23 |
Correct |
273 ms |
13952 KB |
Output is correct |
24 |
Correct |
271 ms |
13908 KB |
Output is correct |