이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 200001;
int n, q;
struct Tree {
vector<int> tree;
Tree() {
tree.resize(2*MAXN);
}
void upd(int u, int k) {
u += n;
tree[u] = k;
for (u /= 2; u >= 1; u /= 2) {
tree[u] = tree[2*u] ^ tree[2*u+1];
}
}
int qry(int l, int r) {
l += n; r += n;
int res = 0;
while (l <= r) {
if (l % 2 == 1) res ^= tree[l++];
if (r % 2 == 0) res ^= tree[r--];
l /= 2; r /= 2;
}
return res;
}
};
void solve(){
cin >> n >> q;
Tree odd, even;
for (int i = 1; i <= n; i++) {
int x; cin >> x;
if (i & 1)
odd.upd(i, x);
else
even.upd(i, x);
}
while (q--) {
int type, l, r; cin >> type >> l >> r;
if (type == 1) {
if (l & 1)
odd.upd(l, r);
else
even.upd(l, r);
} else {
int len = r - l + 1;
if (len & 1) {
if (l & 1) {
cout << odd.qry(l, r) << "\n";
} else {
cout << even.qry(l, r) << "\n";
}
} else {
cout << "0\n";
}
}
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
solve();
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... |