이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct node {
int i, j;
int val;
node *left, *right;
};
node *build(int i, int j, const vector<int>& a) {
if (i == j) {
return new node{i, j, a[i], nullptr, nullptr};
}
node *left = build(i, (i + j) / 2, a);
node *right = build((i + j) / 2 + 1, j, a);
return new node{i, j, (left->val ^ right->val), left, right};
}
int query(node *cur, int i, int j) {
if (cur->j < i || cur->i > j) {
return 0;
}
if (cur->i >= i && cur->j <= j) {
return cur->val;
}
return query(cur->left, i, j) ^ query(cur->right, i, j);
}
void update(node *cur, int i, int new_val) {
if (cur->j < i || cur->i > i) {
return;
}
if (cur->i == i && cur->j == i) {
cur->val = new_val;
return;
}
update(cur->left, i, new_val);
update(cur->right, i, new_val);
cur->val = cur->left->val ^ cur->right->val;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> odd_in(n + 1), even_in(n + 1);
for (int i = 1; i <= n; i++) {
if (i % 2 == 0) {
cin >> even_in[i];
} else {
cin >> odd_in[i];
}
}
node *odd = build(1, n, odd_in);
node *even = build(1, n, even_in);
while (q--) {
int t;
cin >> t;
if (t == 1) {
int i, j;
cin >> i >> j;
if (i % 2 == 0) {
update(even, i, j);
} else {
update(odd, i, j);
}
} else {
int l, u;
cin >> l >> u;
if ((u - l + 1) % 2 == 0) {
cout << 0 << '\n';
continue;
}
if (l % 2 == 0) {
cout << query(even, l, u) << '\n';
} else {
cout << query(odd, l, u) << '\n';
}
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |