#include "bits/stdc++.h"
using namespace std;
using ll = long long;
struct node {
int x;
};
struct segtree {
vector<node> tree;
int size;
node def = {0};
node combine(node a, node b) {
return {a.x ^ b.x};
}
void init(int n) {
size = 1;
while (size < n) size *= 2;
tree.assign(2 * size - 1, def);
}
void set(int i, node v, int x, int lx, int rx) {
if (rx - lx == 1) {
tree[x] = v;
return;
}
int m = (lx + rx) / 2;
if (i < m) {
set(i, v, 2 * x + 1, lx, m);
} else {
set(i, v, 2 * x + 2, m, rx);
}
tree[x] = combine(tree[2 * x + 1], tree[2 * x + 2]);
}
void set(int i, node v) {
set(i, v, 0, 0, size);
}
node res(int l, int r, int x, int lx, int rx) {
if (l >= rx || lx >= r) {
return def;
}
if (lx >= l && rx <= r) {
return tree[x];
}
int m = (lx + rx) / 2;
node s1 = res(l, r, 2 * x + 1, lx, m);
node s2 = res(l, r, 2 * x + 2, m, rx);
return combine(s1, s2);
}
node res(int l, int r) {
return res(l, r, 0, 0, size);
}
};
void solve() {
int n, q;
cin >> n >> q;
vector<int> a(n);
segtree st0, st1;
st0.init(n);
st1.init(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i & 1) {
st1.set(i, {a[i]});
} else {
st0.set(i, {a[i]});
}
}
while (q--) {
int c;
cin >> c;
if (c == 1) {
int i, j;
cin >> i >> j;
if ((i - 1) & 1) {
st1.set(i - 1, {j});
} else {
st0.set(i - 1, {j});
}
} else {
int l, r;
cin >> l >> r;
if ((l & 1) != (r & 1)) {
cout << "0\n";
} else {
if ((l - 1) & 1) {
cout << st1.res(l - 1, r).x << '\n';
} else {
cout << st0.res(l - 1, r).x << '\n';
}
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int test = 1;
// cin >> test;
while (test--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
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 |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
6372 KB |
Output is correct |
2 |
Correct |
117 ms |
11212 KB |
Output is correct |
3 |
Correct |
103 ms |
11224 KB |
Output is correct |
4 |
Correct |
99 ms |
10844 KB |
Output is correct |
5 |
Correct |
101 ms |
10832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
3 ms |
596 KB |
Output is correct |
15 |
Correct |
105 ms |
6372 KB |
Output is correct |
16 |
Correct |
117 ms |
11212 KB |
Output is correct |
17 |
Correct |
103 ms |
11224 KB |
Output is correct |
18 |
Correct |
99 ms |
10844 KB |
Output is correct |
19 |
Correct |
101 ms |
10832 KB |
Output is correct |
20 |
Correct |
102 ms |
10976 KB |
Output is correct |
21 |
Correct |
104 ms |
10956 KB |
Output is correct |
22 |
Correct |
100 ms |
10968 KB |
Output is correct |
23 |
Correct |
100 ms |
10792 KB |
Output is correct |
24 |
Correct |
101 ms |
10832 KB |
Output is correct |