#include <bits/stdc++.h>
#include <cmath>
using namespace std;
typedef unsigned long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
struct Seg {
ll val = INF;
ll l, r, mid; // responisble for [l,r)
Seg* lp, * rp;
Seg(ll l, ll r) : l(l), r(r), mid((l + r) / 2) {
if (l + 1 < r) {
lp = new Seg(l, mid);
rp = new Seg(mid, r);
}
}
void pull() {
val = lp->val ^ rp->val;
}
void update(ll i, ll x) {
if (l + 1 == r) {
val = x;
return;
}
if (i < mid) lp->update(i, x);
else rp->update(i, x);
pull();
}
ll query(ll a, ll b) { // xor of [a,b)
if (a >= r || b <= l) return 0; // [a,b) and [l,r) are disjoll
if (a <= l && r <= b) return val; // [l,r) is inside [a,b)
return lp->query(a, b) ^ rp->query(a, b);
}
};
int main() {
ll n, q;
cin >> n >> q;
Seg seg(0, n / 2 + 1);
Seg seg1(0, n / 2 + 1);
ll g;
for (ll i = 0; i < n; i++) {
cin >> g;
if ((i + 1) % 2 == 1) {
seg1.update(i / 2, g);
}
else
seg.update(i / 2, g);
}
while (q--) {
ll op;
cin >> op;
if (op == 1) {
ll i, j;
cin >> i >> j;
i--;
if ((i + 1) % 2 == 1)
seg1.update(i / 2, j);
else
seg.update(i / 2, j);
}
else {
ll l, r;
cin >> l >> r;
l--, r--;
if ((r - l + 1) % 2 == 0)
cout << 0 << endl;
else {
if ((l + 1) % 2 == 1) {
cout << seg1.query(l / 2, r / 2 + 1) << endl;
}
else {
cout << seg.query(l / 2, r / 2 + 1) << endl;
}
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
13 ms |
972 KB |
Output is correct |
12 |
Correct |
15 ms |
1044 KB |
Output is correct |
13 |
Correct |
18 ms |
1028 KB |
Output is correct |
14 |
Correct |
16 ms |
1032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
764 ms |
27152 KB |
Output is correct |
2 |
Correct |
758 ms |
31548 KB |
Output is correct |
3 |
Correct |
759 ms |
31400 KB |
Output is correct |
4 |
Correct |
663 ms |
30976 KB |
Output is correct |
5 |
Correct |
661 ms |
30916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
13 ms |
972 KB |
Output is correct |
12 |
Correct |
15 ms |
1044 KB |
Output is correct |
13 |
Correct |
18 ms |
1028 KB |
Output is correct |
14 |
Correct |
16 ms |
1032 KB |
Output is correct |
15 |
Correct |
764 ms |
27152 KB |
Output is correct |
16 |
Correct |
758 ms |
31548 KB |
Output is correct |
17 |
Correct |
759 ms |
31400 KB |
Output is correct |
18 |
Correct |
663 ms |
30976 KB |
Output is correct |
19 |
Correct |
661 ms |
30916 KB |
Output is correct |
20 |
Correct |
597 ms |
31088 KB |
Output is correct |
21 |
Correct |
602 ms |
31148 KB |
Output is correct |
22 |
Correct |
615 ms |
31204 KB |
Output is correct |
23 |
Correct |
641 ms |
31044 KB |
Output is correct |
24 |
Correct |
661 ms |
31060 KB |
Output is correct |