#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const int M = 4 * N;
int a[N], st[M][2];
void build(int node, int l, int r) {
if (l > r) return;
if (l == r) {
st[node][l % 2] = a[l];
return;
}
int mid = l + r >> 1;
build(node * 2, l, mid);
build(node * 2 + 1, mid + 1, r);
st[node][0] = st[node * 2][0] ^ st[node * 2 + 1][0];
st[node][1] = st[node * 2][1] ^ st[node * 2 + 1][1];
}
void update(int node, int l, int r, int pos) {
if (l > r) {
return;
}
if (l == r) {
st[node][l % 2] = a[l];
return;
}
int mid = l + r >> 1;
if (pos <= mid) update(node * 2, l, mid, pos);
else update(node * 2 + 1, mid + 1, r, pos);
st[node][0] = st[node * 2][0] ^ st[node * 2 + 1][0];
st[node][1] = st[node * 2][1] ^ st[node * 2 + 1][1];
}
int get(int node, int l, int r, int ll, int rr, int p) {
if (l > r || l > rr || r < ll) return 0;
if (ll <= l && r <= rr) return st[node][p];
int mid = l + r >> 1;
return get(node * 2, l, mid, ll, rr, p) ^ get(node * 2 + 1, mid + 1, r, ll, rr, p);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
build(1, 0, n - 1);
while (q--) {
int foo;
cin >> foo;
if (foo == 1) {
int pos, x;
cin >> pos >> x;
--pos;
a[pos] = x;
update(1, 0, n - 1, pos);
} else {
int l, r;
cin >> l >> r;
--l, --r;
if (l % 2 != r % 2) {
cout << 0 << '\n';
continue;
}
cout << get(1, 0, n - 1, l, r, l % 2) << '\n';
}
}
return 0;
}
Compilation message
xoranges.cpp: In function 'void build(int, int, int)':
xoranges.cpp:16:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
16 | int mid = l + r >> 1;
| ~~^~~
xoranges.cpp: In function 'void update(int, int, int, int)':
xoranges.cpp:31:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
31 | int mid = l + r >> 1;
| ~~^~~
xoranges.cpp: In function 'int get(int, int, int, int, int, int)':
xoranges.cpp:41:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
41 | int mid = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
588 KB |
Output is correct |
12 |
Correct |
4 ms |
588 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
4 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
10068 KB |
Output is correct |
2 |
Correct |
193 ms |
11204 KB |
Output is correct |
3 |
Correct |
171 ms |
11224 KB |
Output is correct |
4 |
Correct |
150 ms |
10796 KB |
Output is correct |
5 |
Correct |
146 ms |
10832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
588 KB |
Output is correct |
12 |
Correct |
4 ms |
588 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
4 ms |
588 KB |
Output is correct |
15 |
Correct |
170 ms |
10068 KB |
Output is correct |
16 |
Correct |
193 ms |
11204 KB |
Output is correct |
17 |
Correct |
171 ms |
11224 KB |
Output is correct |
18 |
Correct |
150 ms |
10796 KB |
Output is correct |
19 |
Correct |
146 ms |
10832 KB |
Output is correct |
20 |
Correct |
163 ms |
10912 KB |
Output is correct |
21 |
Correct |
209 ms |
10960 KB |
Output is correct |
22 |
Correct |
176 ms |
10892 KB |
Output is correct |
23 |
Correct |
169 ms |
10788 KB |
Output is correct |
24 |
Correct |
157 ms |
10820 KB |
Output is correct |