#include <bits/stdc++.h>
using namespace std;
void build(vector<int>& segTree, vector<int>& a, int x, int l, int r) {
if (l == r) {
segTree[x] = a[l];
return;
}
int mid = (l+r)/2;
build(segTree, a, 2*x, l, mid);
build(segTree, a, 2*x+1, mid+1, r);
segTree[x] = segTree[2*x] ^ segTree[2*x+1];
}
void update(vector<int>& segTree, vector<int>& a, int x, int l, int r, int i, int v) {
if (l == r) {
segTree[x] = a[l] = v;
return;
}
int mid = (l+r)/2;
if (i <= mid) {
update(segTree, a, 2*x, l, mid, i, v);
} else{
update(segTree, a, 2*x+1, mid+1, r, i, v);
}
segTree[x] = segTree[2*x] ^ segTree[2*x+1];
}
int getRange(vector<int>& segTree, int x, int l, int r, int lb, int rb) {
if (rb <= l or r <= lb) {
return 0;
} else if (lb <= l and r <= rb) {
return segTree[x];
} else {
int mid = (l+r)/2;
int xor1 = getRange(segTree, 2*x, l, mid, lb, rb);
int xor2 = getRange(segTree, 2*x+1, mid+1, r, lb, rb);
return xor1 ^ xor2;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, n1, n2, q;
vector<int> a, a1, a2;
vector<int> segTree1, segTree2;
int type, pos, val, l, r;
cin >> n >> q;
a = vector<int>(n);
for (int& i: a) cin >> i;
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
a1.push_back(a[i]); // 0 2 4
} else {
a2.push_back(a[i]); // 1 3 5
}
}
n1 = a1.size();
n2 = a2.size();
segTree1 = vector<int>(4*n1, 0);
segTree2 = vector<int>(4*n2, 0);
build(segTree1, a1, 1, 0, n1-1);
if (!a2.empty()) build(segTree2, a2, 1, 0, n2-1);
while (q--) {
cin >> type;
if (type == 1) { // rescan
cin >> pos >> val;
pos--;
a[pos] = val;
if (pos % 2 == 0) {
update(segTree1, a1, 1, 0, n1-1, pos/2, val);
} else {
update(segTree2, a2, 1, 0, n2-1, pos/2, val);
}
}
else { // query
cin >> l >> r;
l--; r--;
int range = r-l+1;
if (l == r) {
cout << a[l] << '\n';
} else if (range % 2 == 0) {
cout << "0\n";
} else {
if (l % 2 == 0) {
cout << getRange(segTree1, 1, 0, n1-1, l/2, r/2) << '\n';
} else {
cout << getRange(segTree2, 1, 0, n2-1, l/2, r/2) << '\n';
}
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
111 ms |
6428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |