#include <bits/stdc++.h>
#define int long long
using namespace std;
struct Segtree{
int n;
vector<pair<int, int>> data;
Segtree(const vector<int>& v) {
n = v.size();
data = vector<pair<int, int>>(4*n);
build(v, 1, 0, n);
}
public:
void set(int i, int x) {
set(i, x, 1, 0, n);
}
int get(int beg, int ed) {
return get(beg, ed, 1, 0, n).first;
}
private:
pair<int, int> get_data(pair<int, int> left, pair<int, int> right, int ll) { // ll = left length
//cerr << "{" << left.first << " | " << left.second << "}, {" << right.first << " | " << right.second << "}\n";
//cerr << ll << "\n";
if (ll <= 0) {
return right;
} else if (ll % 2 == 0) {
return make_pair(left.first ^ right.first, left.second ^ right.second);
} else {
return make_pair(left.first ^ right.second, left.second ^ right.first);
}
}
void update(int pos, int ll) {
data[pos] = get_data(data[pos*2], data[pos*2+1], ll);
}
void build(const vector<int>& v, int pos, int left, int right) {
if (left+1 == right) {
data[pos] = make_pair(v[left], 0);
} else {
int mid = (left + right) / 2;
build(v, pos*2, left, mid);
build(v, pos*2+1, mid, right);
update(pos, mid-left);
}
}
void set(int i, int x, int pos, int left, int right) {
if (left+1 == right) {
data[pos] = make_pair(x, 0);
} else {
int mid = (left + right) / 2;
if (i < mid) {
set(i, x, pos*2, left, mid);
} else {
set(i, x, pos*2+1, mid, right);
}
update(pos, mid-left);
}
}
pair<int, int> get(int beg, int ed, int pos, int left, int right) {
if (beg <= left && ed >= right) {
return data[pos];
} else if (beg >= right || ed <= left) {
return make_pair(0, 0);
} else {
int mid = (left + right) / 2;
return get_data(get(beg, ed, pos*2, left, mid),
get(beg, ed, pos*2+1, mid, right),
mid-max(left, beg));
}
}
};
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int i=0; i<n; i++) {
cin >> a[i];
}
Segtree seg(a);
for (int idx=0; idx<q; idx++) {
int event;
cin >> event;
if (event == 1) {
int i, j;
cin >> i >> j;
seg.set(i-1, j);
} else {
int l, u;
cin >> l >> u;
if ((u - l) % 2 == 1) {
cout << 0 << "\n";
} else {
cout << seg.get(l-1, u) << "\n";
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
716 KB |
Output is correct |
12 |
Correct |
4 ms |
716 KB |
Output is correct |
13 |
Correct |
4 ms |
716 KB |
Output is correct |
14 |
Correct |
4 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
15564 KB |
Output is correct |
2 |
Correct |
176 ms |
20432 KB |
Output is correct |
3 |
Correct |
175 ms |
20416 KB |
Output is correct |
4 |
Correct |
148 ms |
20032 KB |
Output is correct |
5 |
Correct |
150 ms |
20096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
716 KB |
Output is correct |
12 |
Correct |
4 ms |
716 KB |
Output is correct |
13 |
Correct |
4 ms |
716 KB |
Output is correct |
14 |
Correct |
4 ms |
716 KB |
Output is correct |
15 |
Correct |
175 ms |
15564 KB |
Output is correct |
16 |
Correct |
176 ms |
20432 KB |
Output is correct |
17 |
Correct |
175 ms |
20416 KB |
Output is correct |
18 |
Correct |
148 ms |
20032 KB |
Output is correct |
19 |
Correct |
150 ms |
20096 KB |
Output is correct |
20 |
Correct |
165 ms |
20168 KB |
Output is correct |
21 |
Correct |
167 ms |
20140 KB |
Output is correct |
22 |
Correct |
170 ms |
20144 KB |
Output is correct |
23 |
Correct |
151 ms |
20044 KB |
Output is correct |
24 |
Correct |
150 ms |
20036 KB |
Output is correct |