#include <iostream>
#include <queue>
using namespace std;
vector<vector<int> > x;
int N, Q;
struct Segment_tree{
vector<int> st;
void init_segment_tree(int N){
st.assign(4 * N + 1, 0);
}
void build_segment_tree(int p, int l, int r, int k){
if(l == r){
st[p] = x[k][l];
return;
}
int m = (l + r) / 2;
build_segment_tree(2 * p, l, m, k);
build_segment_tree(2 * p + 1, m + 1, r, k);
st[p] = st[2 * p] ^ st[2 * p + 1];
}
void update_segment_tree(int p, int l, int r, int k, int i){
if(l == r){
st[p] = x[k][l];
return;
}
int m = (l + r) / 2;
if(i <= m)
update_segment_tree(2 * p, l, m, k, i);
else
update_segment_tree(2 * p + 1, m + 1, r, k, i);
st[p] = st[2 * p] ^ st[2 * p + 1];
}
int range_query(int p, int l, int r, int ql, int qr){
if(ql <= l && r <= qr)
return st[p];
if(r < ql || qr < l) return 0;
int m = (r + l) / 2;
return range_query(2 * p, l, m, ql, qr) ^ range_query(2 * p + 1, m + 1, r, ql, qr);
}
};
int main(){
cin >> N >> Q;
x.assign(2, vector<int> ());
x[0].push_back(0);
x[1].push_back(0);
int p;
for(int i = 1; i <= N; ++i){
cin >> p;
x[i % 2].push_back(p);
}
Segment_tree stree[2];
for(int i = 0; i < 2; ++i){
stree[i].init_segment_tree(x[i].size());
stree[i].build_segment_tree(1, 1, x[i].size() - 1, i);
}
int t, a, b;
while(Q--){
cin >> t >> a >> b;
if(t == 1){
x[a % 2][a / 2 + a % 2] = b;
stree[a % 2].update_segment_tree(1, 1, x[a % 2].size() - 1, a % 2, a / 2 + a % 2);
}
else{
if((b - a + 1) % 2 == 0){
cout << 0 << '\n';
continue;
}
else
cout << stree[a % 2].range_query(1, 1, x[a % 2].size() - 1, a / 2 + a % 2, b / 2 + b % 2) << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
14 ms |
448 KB |
Output is correct |
12 |
Correct |
15 ms |
340 KB |
Output is correct |
13 |
Correct |
13 ms |
440 KB |
Output is correct |
14 |
Correct |
15 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
516 ms |
5584 KB |
Output is correct |
2 |
Correct |
565 ms |
5516 KB |
Output is correct |
3 |
Correct |
535 ms |
5532 KB |
Output is correct |
4 |
Correct |
546 ms |
5588 KB |
Output is correct |
5 |
Correct |
532 ms |
5516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
14 ms |
448 KB |
Output is correct |
12 |
Correct |
15 ms |
340 KB |
Output is correct |
13 |
Correct |
13 ms |
440 KB |
Output is correct |
14 |
Correct |
15 ms |
340 KB |
Output is correct |
15 |
Correct |
516 ms |
5584 KB |
Output is correct |
16 |
Correct |
565 ms |
5516 KB |
Output is correct |
17 |
Correct |
535 ms |
5532 KB |
Output is correct |
18 |
Correct |
546 ms |
5588 KB |
Output is correct |
19 |
Correct |
532 ms |
5516 KB |
Output is correct |
20 |
Correct |
417 ms |
5028 KB |
Output is correct |
21 |
Correct |
390 ms |
4940 KB |
Output is correct |
22 |
Correct |
517 ms |
4988 KB |
Output is correct |
23 |
Correct |
528 ms |
5476 KB |
Output is correct |
24 |
Correct |
496 ms |
5556 KB |
Output is correct |