#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000000
struct SegTree{
vector<int> ve, tr;
SegTree(int n, vector<int> vec){
ve = vec;
tr.assign(4 * n + 1, -1);
build(1, 0, n - 1);
}
void build(int v, int l, int r){
if (l == r){
tr[v - 1] = ve[l];
}
else{
int mid = (l + r) / 2;
build(v * 2, l, mid);
build(v * 2 + 1, mid + 1, r);
tr[v - 1] = (tr[v * 2 - 1]) ^ (tr[v * 2]);
}
}
void update(int v, int l, int r, int po, int va){
if (l == r){
tr[v - 1] = va;
}
else{
int mid = (l + r) / 2;
if (po <= mid){
update(v * 2, l, mid, po, va);
}
else{
update(v * 2 + 1, mid + 1, r, po, va);
}
tr[v - 1] = (tr[v * 2 - 1]) ^ (tr[v * 2]);
}
}
int query(int v, int l, int r, int ql, int qr){
if (ql <= l && r <= qr){
return tr[v - 1];
}
else if (r < ql || l > qr){
return 0;
}
else{
int mid = (l + r) / 2;
return query(v * 2, l, mid, ql, qr) ^ query(v * 2 + 1, mid + 1, r, ql, qr);
}
}
};
int main(){
int n, a, q, t, l, r;
cin>>n>>q;
vector<int> ve0(n , 0), ve1(n, 0);
for (int i = 0; i < n; i++){
cin>>a;
if (i % 2 == 0){
ve0[i] = a;
}
else{
ve1[i] = a;
}
}
SegTree tr0(n, ve0), tr1(n, ve1);
for (int i = 0; i < q; i++){
cin>>t>>l>>r;
if (t == 1){
l--;
if (l % 2 == 0){
tr0.update(1, 0, n - 1, l, r);
}
else{
tr1.update(1, 0, n - 1, l, r);
}
}
else{
l--, r--;
if ((r - l + 1) % 2 == 0){
cout<<0<<"\n";
}
else{
if (l % 2 == 0){
cout<<tr0.query(1, 0, n - 1, l, r)<<"\n";
}
else{
cout<<tr1.query(1, 0, n - 1, l, r)<<"\n";
}
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
8 ms |
604 KB |
Output is correct |
12 |
Correct |
8 ms |
816 KB |
Output is correct |
13 |
Correct |
10 ms |
600 KB |
Output is correct |
14 |
Correct |
10 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
437 ms |
16424 KB |
Output is correct |
2 |
Correct |
449 ms |
16428 KB |
Output is correct |
3 |
Correct |
448 ms |
16720 KB |
Output is correct |
4 |
Correct |
427 ms |
16184 KB |
Output is correct |
5 |
Correct |
420 ms |
16192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
8 ms |
604 KB |
Output is correct |
12 |
Correct |
8 ms |
816 KB |
Output is correct |
13 |
Correct |
10 ms |
600 KB |
Output is correct |
14 |
Correct |
10 ms |
600 KB |
Output is correct |
15 |
Correct |
437 ms |
16424 KB |
Output is correct |
16 |
Correct |
449 ms |
16428 KB |
Output is correct |
17 |
Correct |
448 ms |
16720 KB |
Output is correct |
18 |
Correct |
427 ms |
16184 KB |
Output is correct |
19 |
Correct |
420 ms |
16192 KB |
Output is correct |
20 |
Correct |
378 ms |
16388 KB |
Output is correct |
21 |
Correct |
329 ms |
16160 KB |
Output is correct |
22 |
Correct |
330 ms |
16348 KB |
Output is correct |
23 |
Correct |
416 ms |
16272 KB |
Output is correct |
24 |
Correct |
414 ms |
16716 KB |
Output is correct |