#include <bits/stdc++.h>
using namespace std;
struct Segtree {
int n, d;
vector<int> st;
Segtree(const vector<int>& a, int c) {
n = (int)a.size();
st = vector<int>(4*n);
d = c;
build(1, 0, n-1, a);
}
void build(int p, int l, int r, const vector<int>& a) {
if (l == r) {
if (l%2 == d) st[p] = a[l];
else st[p] = 0;
} else {
int m = (l+r)/2;
build(2*p, l, m, a);
build(2*p+1, m+1, r, a);
st[p] = st[2*p]^st[2*p+1];
}
}
void change(int p, int l, int r, int i, int x) {
if (l == r) {
if (l%2 == d) st[p] = x;
else st[p] = 0;
} else {
int m = (l+r)/2;
if (i <= m) change(2*p, l, m, i, x);
else change(2*p+1, m+1, r, i, x);
st[p] = st[2*p]^st[2*p+1];
}
}
int Xor(int p, int l, int r, int i, int j) {
if (i > j) return 0;
if (i == l && j == r) return st[p];
int m = (l+r)/2;
return Xor(2*p, l, m, i, min(m, j))^Xor(2*p+1, m+1, r, max(i, m+1), j);
}
void change(int i, int x) { change(1, 0, n-1, i, x); }
int Xor(int i, int j) { return Xor(1, 0, n-1, i, j); }
};
int main() {
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
Segtree St0(a, 0), St1(a, 1);
while (q--) {
int t; cin >> t;
if (t == 1) {
int p, x; cin >> p >> x;
--p;
if (p%2) St1.change(p, x);
else St0.change(p, x);
} else {
int l, r; cin >> l >> r; --l; --r;
if ((r-l+1)%2) {
if (l%2) cout << St1.Xor(l, r) << endl;
else cout << St0.Xor(l, r) << endl;
} else cout << 0 << endl;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
7 ms |
604 KB |
Output is correct |
12 |
Correct |
7 ms |
604 KB |
Output is correct |
13 |
Correct |
9 ms |
740 KB |
Output is correct |
14 |
Correct |
9 ms |
720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
401 ms |
13496 KB |
Output is correct |
2 |
Correct |
383 ms |
13392 KB |
Output is correct |
3 |
Correct |
387 ms |
13392 KB |
Output is correct |
4 |
Correct |
373 ms |
13140 KB |
Output is correct |
5 |
Correct |
417 ms |
13064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
7 ms |
604 KB |
Output is correct |
12 |
Correct |
7 ms |
604 KB |
Output is correct |
13 |
Correct |
9 ms |
740 KB |
Output is correct |
14 |
Correct |
9 ms |
720 KB |
Output is correct |
15 |
Correct |
401 ms |
13496 KB |
Output is correct |
16 |
Correct |
383 ms |
13392 KB |
Output is correct |
17 |
Correct |
387 ms |
13392 KB |
Output is correct |
18 |
Correct |
373 ms |
13140 KB |
Output is correct |
19 |
Correct |
417 ms |
13064 KB |
Output is correct |
20 |
Correct |
300 ms |
13136 KB |
Output is correct |
21 |
Correct |
282 ms |
13112 KB |
Output is correct |
22 |
Correct |
287 ms |
13092 KB |
Output is correct |
23 |
Correct |
368 ms |
13140 KB |
Output is correct |
24 |
Correct |
392 ms |
13140 KB |
Output is correct |