This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using i64 = long long;
struct SegmentTree {
int n;
std::vector<int> t;
SegmentTree(int n) : n(n), t(2 * n) {}
void modify(int p, int val) {
for (t[p += n] = val; p > 1; p >>= 1) {
t[p >> 1] = t[p] ^ t[p ^ 1];
}
}
int get(int l, int r) {
int res = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1) {
res ^= t[l++];
}
if (r & 1) {
res ^= t[--r];
}
}
return res;
}
};
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, q;
std::cin >> n >> q;
std::vector<int> a(n);
SegmentTree s1(n), s2(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
if (i % 2 == 0) {
s1.modify(i, a[i]);
} else {
s2.modify(i, a[i]);
}
}
while (q--) {
int type;
std::cin >> type;
if (type == 1) {
int p, v;
std::cin >> p >> v;
p--;
if (p % 2 == 0) {
s1.modify(p, v);
} else {
s2.modify(p, v);
}
a[p] = v;
} else {
int l, r;
std::cin >> l >> r;
l--;
if ((r - l) % 2 == 0) {
std::cout << 0 << "\n";
} else if (l % 2 == 0) {
std::cout << s1.get(l, r) << "\n";
} else {
std::cout << s2.get(l, r) << "\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... |