#include <bits/stdc++.h>
using namespace std;
struct segtree {
struct node {
long long val;
};
vector<node> tree;
int sz;
node ZERO = {0};
node combine(node a, node b) {
node result;
result.val = a.val ^ b.val;
return result;
}
void init(int n) {
sz = 1;
while(sz < n) {
sz *= 2;
}
tree.assign(2 * sz - 1, ZERO);
}
void set(int pos, node val, int x, int lx, int rx) {
if(rx - lx == 1) {
tree[x] = val;
return;
}
int mid = (lx + rx) / 2;
if(pos < mid) {
set(pos, val, x * 2 + 1, lx, mid);
}
else {
set(pos, val, x * 2 + 2, mid, rx);
}
tree[x] = combine(tree[x * 2 + 1], tree[x * 2 + 2]);
}
void set(int pos, long long val) {
node v = {val};
set(pos, v, 0, 0, sz);
}
node get(int l, int r, int x, int lx, int rx) {
if(l >= rx || lx >= r) {
return ZERO;
}
if(lx >= l && rx <= r) {
return tree[x];
}
int mid = (lx + rx) / 2;
return combine(get(l, r, x * 2 + 1, lx, mid), get(l, r, x * 2 + 2, mid, rx));
}
long long get(int l, int r) {
return get(l, r + 1, 0, 0, sz).val;
}
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
segtree sge, sgo;
sge.init(n / 2 + n % 2);
sgo.init(n / 2);
for(int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
if(i % 2 == 1) {
sgo.set(i / 2, tmp);
}
else {
sge.set(i / 2, tmp);
}
}
while(q--) {
int x;
cin >> x;
if(x == 2) {
int l, r;
cin >> l >> r;
l--;
r--;
if((r - l + 1) % 2 == 0) {
cout << 0 << '\n';
continue;
}
if(l % 2 == 1) {
cout << sgo.get(l / 2, r / 2) << '\n';
}
else {
cout << sge.get(l / 2, r / 2) << '\n';
}
}
else {
int i, j;
cin >> i >> j;
i--;
if(i % 2 == 0) {
sge.set(i / 2, j);
}
else {
sgo.set(i / 2, j);
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
456 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
5628 KB |
Output is correct |
2 |
Correct |
123 ms |
5612 KB |
Output is correct |
3 |
Correct |
119 ms |
5576 KB |
Output is correct |
4 |
Correct |
111 ms |
5556 KB |
Output is correct |
5 |
Correct |
113 ms |
5576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
456 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
124 ms |
5628 KB |
Output is correct |
16 |
Correct |
123 ms |
5612 KB |
Output is correct |
17 |
Correct |
119 ms |
5576 KB |
Output is correct |
18 |
Correct |
111 ms |
5556 KB |
Output is correct |
19 |
Correct |
113 ms |
5576 KB |
Output is correct |
20 |
Correct |
132 ms |
10196 KB |
Output is correct |
21 |
Correct |
125 ms |
10124 KB |
Output is correct |
22 |
Correct |
143 ms |
10176 KB |
Output is correct |
23 |
Correct |
117 ms |
10060 KB |
Output is correct |
24 |
Correct |
123 ms |
10012 KB |
Output is correct |