#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
#define debug(x) cout << #x << " = " << x << endl
#define pb push_back
#define eb emplace_back
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int mod = 1e9 + 7;
using namespace std;
void setIO() {
ios_base::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
}
struct SegTree {
int n;
vector<int> v;
vector<ll> tree;
SegTree(vector<int> const &v) {
this->n = sz(v);
this->v = v;
tree.resize(3*sz(v) + 2);
build(1, 0, n-1);
}
void build(int node, int l, int r) {
if(l == r) {
tree[node] = v[l];
} else {
int mid = (l + r) / 2;
build(2*node, l, mid);
build(2*node+1, mid+1, r);
tree[node] = tree[2*node] ^ tree[2*node+1];
}
}
ll query(int node, int tl, int tr, int l, int r) {
if(l > r) return 0;
if(l == tl && r == tr) return tree[node];
int tm = (tl + tr) / 2;
return query(2*node, tl, tm, l, min(r, tm)) ^ query(2*node+1, tm+1, tr, max(l, tm+1), r);
}
void update(int node, int l, int r, int pos, int val) {
if(l == r) {
tree[node] = val;
v[l] = val;
} else {
int mid = (l + r) / 2;
if(l <= pos && pos <= mid)
update(2*node, l, mid, pos, val);
else
update(2*node+1, mid+1, r, pos, val);
tree[node] = tree[2*node] ^ tree[2*node+1];
}
}
};
int main() {
setIO();
int n, q;
cin >> n >> q;
vector<int> v(n), even, odd;
for(int i=0; i<n; i++) {
cin >> v[i];
if(i & 1) even.pb(v[i]);
else odd.pb(v[i]);
}
SegTree tree1(odd), tree2(even);
while(q--) {
int t;
cin >> t;
if(t == 1) {
int a, b;
cin >> a >> b;
if(a % 2 == 1) {
tree1.update(1, 0, n/2, a/2, b);
} else {
if(n % 2 == 0)
tree2.update(1, 0, n/2, (a-1)/2, b);
else
tree2.update(1, 0, n/2-1, (a-1)/2, b);
}
} else {
int a, b;
cin >> a >> b;
if(b-a % 2 == 0) cout << 0 << '\n';
else {
if(a % 2 == 1) {
cout << tree1.query(1, 0, n/2, a/2, b/2) << '\n';
} else {
if(n % 2 == 0)
cout << tree2.query(1, 0, n/2, (a-1)/2, (b-1)/2) << '\n';
else
cout << tree2.query(1, 0, n/2-1, (a-1)/2, (b-1)/2) << '\n';
}
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
124 ms |
14368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |