#include <bits/stdc++.h>
using namespace std;
const int nmax = 5e5 + 1;
struct AINT {
int aint[nmax * 4];
void init() {
memset(aint, 0, sizeof(aint));
}
void update(int nod, int st, int dr, int poz, int val) {
if(st == dr) {
aint[nod] = val;
return;
}
int mid = (st + dr) / 2;
if(poz <= mid) {
update(nod * 2, st, mid, poz, val);
} else {
update(nod * 2 + 1, mid + 1, dr, poz, val);
}
aint[nod] = (aint[nod * 2] ^ aint[nod * 2 + 1]);
}
int query(int nod, int st, int dr, int l, int r) {
if(l <= st && dr <= r) {
return aint[nod];
}
int mid = (st + dr) / 2, a1 = 0, a2 = 0;
if(l <= mid) {
a1 = query(nod * 2, st, mid, l, min(r, mid));
}
if(r > mid) {
a2 = query(nod * 2 + 1, mid + 1, dr, max(l, mid + 1), r);
}
return (a1 ^ a2);
}
};
int main() {
AINT s1, s2;
/*
for(int i = 1; i <= 5; i ++) {
s1.update(1, 1, 5, i, i);
}
for(int i = 1; i <= 5; i ++) {
cout << s1.query(1, 1, 5, i, i) << ' ';
}
cout << '\n';
*/
s1.init();
s2.init();
int n, q;
cin >> n >> q;
int ok = n % 2;
for(int i = 1; i <= n; i ++) {
int a;
cin >> a;
if(i % 2 == 0) {
s1.update(1, 1, n / 2, i / 2, a);
// cout << s1.query(1, 1, n / 2 + 1, i / 2, i / 2) << " ";
} else {
s2.update(1, 1, n / 2 + ok, i / 2 + 1, a);
// cout << s2.query(1, 1, n / 2 + 1, i / 2 + 1, i / 2 + 1) << " ";
}
}
// cout << '\n';
// cout << "sirul: ";
/*
for(int ii = 1; ii <= n; ii ++) {
if(ii % 2 == 0) {
cout << s1.query(1, 1, n / 2, ii / 2, ii / 2) << " ";
} else {
cout << s2.query(1, 1, n / 2 + ok, ii / 2 + 1, ii / 2 + 1) << " ";
}
}
cout << '\n';
*/
for(int i = 1; i <= q; i ++) {
int t, a, b;
cin >> t >> a >> b;
if(t == 1) {
if(a % 2 == 0) {
s1.update(1, 1, n / 2, a / 2, b);
} else {
s2.update(1, 1, n / 2 + ok, a / 2 + 1, b);
}
} else {
if((b - a + 1) % 2 == 0) {
cout << "0\n";
} else if(a % 2 == 0) {
cout << s1.query(1, 1, n / 2, a / 2, b / 2) << '\n';
} else {
cout << s2.query(1, 1, n / 2 + ok, a / 2 + 1, b / 2 + 1) << '\n';
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
15908 KB |
Output is correct |
2 |
Correct |
9 ms |
15964 KB |
Output is correct |
3 |
Correct |
9 ms |
15952 KB |
Output is correct |
4 |
Correct |
9 ms |
15960 KB |
Output is correct |
5 |
Correct |
9 ms |
15964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
15964 KB |
Output is correct |
2 |
Correct |
10 ms |
15860 KB |
Output is correct |
3 |
Correct |
9 ms |
15964 KB |
Output is correct |
4 |
Correct |
9 ms |
16216 KB |
Output is correct |
5 |
Correct |
10 ms |
15964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
15908 KB |
Output is correct |
2 |
Correct |
9 ms |
15964 KB |
Output is correct |
3 |
Correct |
9 ms |
15952 KB |
Output is correct |
4 |
Correct |
9 ms |
15960 KB |
Output is correct |
5 |
Correct |
9 ms |
15964 KB |
Output is correct |
6 |
Correct |
9 ms |
15964 KB |
Output is correct |
7 |
Correct |
10 ms |
15860 KB |
Output is correct |
8 |
Correct |
9 ms |
15964 KB |
Output is correct |
9 |
Correct |
9 ms |
16216 KB |
Output is correct |
10 |
Correct |
10 ms |
15964 KB |
Output is correct |
11 |
Correct |
21 ms |
15964 KB |
Output is correct |
12 |
Correct |
16 ms |
15964 KB |
Output is correct |
13 |
Correct |
21 ms |
15960 KB |
Output is correct |
14 |
Correct |
20 ms |
15964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
442 ms |
22044 KB |
Output is correct |
2 |
Correct |
438 ms |
21940 KB |
Output is correct |
3 |
Correct |
459 ms |
22060 KB |
Output is correct |
4 |
Correct |
439 ms |
21896 KB |
Output is correct |
5 |
Correct |
422 ms |
21788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
15908 KB |
Output is correct |
2 |
Correct |
9 ms |
15964 KB |
Output is correct |
3 |
Correct |
9 ms |
15952 KB |
Output is correct |
4 |
Correct |
9 ms |
15960 KB |
Output is correct |
5 |
Correct |
9 ms |
15964 KB |
Output is correct |
6 |
Correct |
9 ms |
15964 KB |
Output is correct |
7 |
Correct |
10 ms |
15860 KB |
Output is correct |
8 |
Correct |
9 ms |
15964 KB |
Output is correct |
9 |
Correct |
9 ms |
16216 KB |
Output is correct |
10 |
Correct |
10 ms |
15964 KB |
Output is correct |
11 |
Correct |
21 ms |
15964 KB |
Output is correct |
12 |
Correct |
16 ms |
15964 KB |
Output is correct |
13 |
Correct |
21 ms |
15960 KB |
Output is correct |
14 |
Correct |
20 ms |
15964 KB |
Output is correct |
15 |
Correct |
442 ms |
22044 KB |
Output is correct |
16 |
Correct |
438 ms |
21940 KB |
Output is correct |
17 |
Correct |
459 ms |
22060 KB |
Output is correct |
18 |
Correct |
439 ms |
21896 KB |
Output is correct |
19 |
Correct |
422 ms |
21788 KB |
Output is correct |
20 |
Correct |
371 ms |
21844 KB |
Output is correct |
21 |
Correct |
343 ms |
21856 KB |
Output is correct |
22 |
Correct |
326 ms |
21840 KB |
Output is correct |
23 |
Correct |
424 ms |
21724 KB |
Output is correct |
24 |
Correct |
411 ms |
21588 KB |
Output is correct |