#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
struct Seg{
vi seg;
int n;
Seg(int m) {
for (n = 1; n < m; n <<= 1);
seg.resize(2 * n);
}
void update(int i, int x) {
seg[i += n] = x;
for (i >>= 1; i; i >>= 1) seg[i] = seg[2 * i] ^ seg[2 * i + 1];
}
int query(int l, int r) {
int ans = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1) ans ^= seg[l++];
if (r & 1) ans ^= seg[--r];
}
return ans;
}
};
int main() {
int n, q;
cin >> n >> q;
vi a(n + 1);
vector<Seg> seg(2, Seg(n + 1));
for (int i = 1; i <= n; i++) {
cin >> a[i];
seg[i & 1].update(i, a[i]);
}
while (q--) {
int type;
cin >> type;
if (type == 1) {
int i, x;
cin >> i >> x;
seg[i & 1].update(i, x);
continue;
}
int l, r;
cin >> l >> r;
if (!((r - l + 1) & 1)) {
cout << 0 << '\n';
continue;
}
cout << seg[(l & 1)].query(l, r + 1) << '\n';
// int ans = 0;
// for (int i = 1; i <= r - l + 1; i++) {
// for (int j = l; j + i - 1 <= r; j++) {
// for (int k = j; k < j + i; k++) {
// ans ^= a[k];
// }
// }
// }
// cout << ans << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
300 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 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 |
292 KB |
Output is correct |
6 |
Correct |
2 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
300 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
2 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
204 KB |
Output is correct |
11 |
Correct |
12 ms |
588 KB |
Output is correct |
12 |
Correct |
11 ms |
588 KB |
Output is correct |
13 |
Correct |
15 ms |
588 KB |
Output is correct |
14 |
Correct |
16 ms |
744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
633 ms |
11220 KB |
Output is correct |
2 |
Correct |
622 ms |
11176 KB |
Output is correct |
3 |
Correct |
632 ms |
11224 KB |
Output is correct |
4 |
Correct |
607 ms |
10836 KB |
Output is correct |
5 |
Correct |
608 ms |
10944 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 |
292 KB |
Output is correct |
6 |
Correct |
2 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
300 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
2 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
204 KB |
Output is correct |
11 |
Correct |
12 ms |
588 KB |
Output is correct |
12 |
Correct |
11 ms |
588 KB |
Output is correct |
13 |
Correct |
15 ms |
588 KB |
Output is correct |
14 |
Correct |
16 ms |
744 KB |
Output is correct |
15 |
Correct |
633 ms |
11220 KB |
Output is correct |
16 |
Correct |
622 ms |
11176 KB |
Output is correct |
17 |
Correct |
632 ms |
11224 KB |
Output is correct |
18 |
Correct |
607 ms |
10836 KB |
Output is correct |
19 |
Correct |
608 ms |
10944 KB |
Output is correct |
20 |
Correct |
473 ms |
10924 KB |
Output is correct |
21 |
Correct |
471 ms |
10944 KB |
Output is correct |
22 |
Correct |
472 ms |
10916 KB |
Output is correct |
23 |
Correct |
603 ms |
10928 KB |
Output is correct |
24 |
Correct |
613 ms |
10936 KB |
Output is correct |