이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back
#define endl '\n'
using namespace std;
const int MOD = 1e9 + 7;
const int N = 2 * 1e5 + 1;
int n, q, a[N], t[4 * N], ty;
void build(int v, int tl, int tr) {
if (tl == tr) {
t[v] = a[tl];
return;
}
int tm = (tl + tr) / 2;
build(v*2, tl, tm); build(v*2+1, tm+1, tr);
t[v] = t[v*2] ^ t[v*2+1];
}
int solve(int v, int tl, int tr, int l, int r) {
if (l > r) return 0;
if (tl == l and tr == r)
return t[v];
int tm = (tl + tr) / 2;
return solve(v*2, tl, tm, l, min(tm, r)) ^ solve(v*2+1, tm+1, tr, max(tm+1, tl), tr);
}
void update(int v, int tl, int tr, int pos, int new_value) {
if (tl == tr) {
t[v] = new_value;
return;
}
int tm = (tl + tr) / 2;
if (pos <= tm) update(v*2, tl, tm, pos, new_value);
else update(v*2+1, tm+1, tr, pos, new_value);
t[v] = t[v*2] ^ t[v*2+1];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
build(1, 0, n - 1);
while(q--) {
cin >> ty;
if (ty & 1) {
int l, r;
cin >> l >> r;
update(1, 0, n - 1, --l, r);
} else {
int l, r;
cin >> l >> r;
cout << solve(1, 0, n-1, --l, --r) << endl;
}
}
}
# | 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... |