이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <random>
#ifndef LOCAL
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
#endif
using namespace std;
typedef long long ll;
typedef double dd;
typedef long double ld;
typedef unsigned int uii;
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void solve();
mt19937_64 mt(1);
int32_t main() {
#ifdef LOCAL
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#else
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
//freopen("amusing.in", "r", stdin);
//freopen("amusing.out", "w", stdout);
#endif
cout << fixed << setprecision(30);
int tests = 1;
//cin >> tests;
while (tests--) {
solve();
}
}
struct point {
uii x;
int l, r;
};
struct SegmentTree {
vector<point> st;
int sz;
explicit SegmentTree(vector<int>& a) {
int n = a.size();
int i2 = 1;
while (i2 < n) {
i2 <<= 1;
}
sz = i2;
st.resize(2 * i2 - 1);
for (int i = i2 - 1; i < 2 * i2 - 1; i++) {
if (i - i2 + 1 < n) {
st[i].x = a[i - i2 + 1];
} else {
st[i].x = 0;
}
st[i].l = i - i2 + 1;
st[i].r = i - i2 + 1;
}
for (int i = i2 - 2; i >= 0; i--) {
st[i] = {st[2 * i + 1].x ^ st[2 * i + 2].x, st[2 * i + 1].l, st[2 * i + 2].r};
}
}
void update(int i, uii c) {
i += sz - 1;
uii d = st[i].x ^ c;
while (i) {
st[i].x ^= d;
i = (i - 1) / 2;
}
st[i].x ^= d;
}
uii get(int l, int r, int i = 0) {
if (st[i].l > r || st[i].r < l) {
return 0;
}
if (st[i].l >= l && st[i].r <= r) {
return st[i].x;
}
return get(l, r, 2 * i + 1) ^ get(l, r, 2 * i + 2);
}
};
void solve() {
int n, q;
cin >> n >> q;
vector<int> a1, a2;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (i % 2) {
a2.push_back(x);
} else {
a1.push_back(x);
}
}
SegmentTree st1(a1), st2(a2);
while (q--) {
int c;
cin >> c;
if (c == 1) {
int i, x;
cin >> i >> x; i--;
if (i % 2) {
st2.update(i / 2, x);
} else {
st1.update(i / 2, x);
}
} else {
int l, r;
cin >> l >> r; l--; r--;
if ((r - l) % 2) {
cout << "0\n";
} else {
if (l % 2) {
cout << st2.get(l / 2, r / 2) << '\n';
} else {
cout << st1.get(l / 2, r / 2) << '\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... |