#include <bits/stdc++.h>
using namespace std;
struct segtree {
struct node {
long long val;
};
vector<node> tree;
int sz;
node ZERO = {0};
node combine(node a, node b) {
node result;
result.val = a.val ^ b.val;
return result;
}
void init(int n) {
sz = 1;
while(sz < n) {
sz *= 2;
}
tree.assign(2 * sz - 1, ZERO);
}
void set(int pos, node val, int x, int lx, int rx) {
if(rx - lx == 1) {
tree[x] = val;
return;
}
int mid = (lx + rx) / 2;
if(pos < mid) {
set(pos, val, x * 2 + 1, lx, mid);
}
else {
set(pos, val, x * 2 + 2, mid, rx);
}
tree[x] = combine(tree[x * 2 + 1], tree[x * 2 + 2]);
}
void set(int pos, long long val) {
node v = {val};
set(pos, v, 0, 0, sz);
}
node get(int l, int r, int x, int lx, int rx) {
if(l >= rx || lx >= r) {
return ZERO;
}
if(lx >= l && rx <= r) {
return tree[x];
}
int mid = (lx + rx) / 2;
return combine(get(l, r, x * 2 + 1, lx, mid), get(l, r, x * 2 + 2, mid, rx));
}
long long get(int l, int r) {
return get(l, r + 1, 0, 0, sz).val;
}
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
segtree sg;
sg.init(n);
for(int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
sg.set(i, tmp);
}
while(q--) {
int x;
cin >> x;
if(x == 2) {
int l, r;
cin >> l >> r;
l--;
r--;
cout << sg.get(l, r) << '\n';
}
else {
int i, j;
cin >> i >> j;
sg.set(i - 1, j);
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
176 ms |
11252 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |