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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
struct Seg{
vi seg;
int n;
Seg(int m) {
for (n = 1; n < m; n <<= 1);
seg.resize(2 * n);
}
void update(int i, int x) {
seg[i += n] = x;
for (i >>= 1; i; i >>= 1) seg[i] = seg[2 * i] ^ seg[2 * i + 1];
}
int query(int l, int r) {
int ans = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1) ans ^= seg[l++];
if (r & 1) ans ^= seg[--r];
}
return ans;
}
};
int main() {
int n, q;
cin >> n >> q;
vi a(n + 1);
vector<Seg> seg(2, Seg(n + 1));
for (int i = 1; i <= n; i++) {
cin >> a[i];
seg[i & 1].update(i, a[i]);
}
while (q--) {
int type;
cin >> type;
if (type == 1) {
int i, x;
cin >> i >> x;
seg[i & 1].update(i, x);
continue;
}
int l, r;
cin >> l >> r;
if (!((r - l + 1) & 1)) {
cout << 0 << '\n';
continue;
}
cout << seg[(l & 1)].query(l, r + 1) << '\n';
// int ans = 0;
// for (int i = 1; i <= r - l + 1; i++) {
// for (int j = l; j + i - 1 <= r; j++) {
// for (int k = j; k < j + i; k++) {
// ans ^= a[k];
// }
// }
// }
// cout << ans << '\n';
}
}
# | 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... |