# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
675666 |
2022-12-27T17:03:12 Z |
Alma |
XORanges (eJOI19_xoranges) |
C++17 |
|
120 ms |
11196 KB |
#include <bits/stdc++.h>
using namespace std;
void build(vector<int>& segTree, vector<int>& a, int x, int l, int r) {
if (l == r) {
segTree[x] = a[l];
return;
}
int mid = (l+r)/2;
build(segTree, a, 2*x, l, mid);
build(segTree, a, 2*x+1, mid+1, r);
segTree[x] = segTree[2*x] ^ segTree[2*x+1];
}
void update(vector<int>& segTree, vector<int>& a, int x, int l, int r, int i, int v) {
if (l == r) {
segTree[x] = a[l] = v;
return;
}
int mid = (l+r)/2;
if (i <= mid) {
update(segTree, a, 2*x, l, mid, i, v);
} else{
update(segTree, a, 2*x+1, mid+1, r, i, v);
}
segTree[x] = segTree[2*x] ^ segTree[2*x+1];
}
int getRange(vector<int>& segTree, int x, int l, int r, int lb, int rb) {
if (rb < l or r < lb) {
return 0;
} else if (lb <= l and r <= rb) {
return segTree[x];
} else {
int mid = (l+r)/2;
int xor1 = getRange(segTree, 2*x, l, mid, lb, rb);
int xor2 = getRange(segTree, 2*x+1, mid+1, r, lb, rb);
return xor1 ^ xor2;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, n1, n2, q;
vector<int> a, a1, a2;
vector<int> segTree1, segTree2;
int type, pos, val, l, r;
cin >> n >> q;
a = vector<int>(n);
for (int& i: a) cin >> i;
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
a1.push_back(a[i]); // 0 2 4
} else {
a2.push_back(a[i]); // 1 3 5
}
}
n1 = a1.size();
n2 = a2.size();
segTree1 = vector<int>(4*n1, 0);
segTree2 = vector<int>(4*n2, 0);
build(segTree1, a1, 1, 0, n1-1);
if (!a2.empty()) build(segTree2, a2, 1, 0, n2-1);
while (q--) {
cin >> type;
if (type == 1) {
cin >> pos >> val;
pos--;
a[pos] = val;
if (pos % 2 == 0) {
update(segTree1, a1, 1, 0, n1-1, pos/2, val);
} else {
update(segTree2, a2, 1, 0, n2-1, pos/2, val);
}
}
else {
cin >> l >> r;
l--; r--;
int range = r-l+1;
if (range % 2 == 0) {
cout << "0\n";
} else {
if (l % 2 == 0) {
cout << getRange(segTree1, 1, 0, n1-1, l/2, r/2) << '\n';
} else {
cout << getRange(segTree2, 1, 0, n2-1, l/2, r/2) << '\n';
}
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
576 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
108 ms |
6384 KB |
Output is correct |
2 |
Correct |
105 ms |
11196 KB |
Output is correct |
3 |
Correct |
120 ms |
11176 KB |
Output is correct |
4 |
Correct |
97 ms |
10932 KB |
Output is correct |
5 |
Correct |
104 ms |
10896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
576 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
3 ms |
596 KB |
Output is correct |
15 |
Correct |
108 ms |
6384 KB |
Output is correct |
16 |
Correct |
105 ms |
11196 KB |
Output is correct |
17 |
Correct |
120 ms |
11176 KB |
Output is correct |
18 |
Correct |
97 ms |
10932 KB |
Output is correct |
19 |
Correct |
104 ms |
10896 KB |
Output is correct |
20 |
Correct |
114 ms |
10944 KB |
Output is correct |
21 |
Correct |
111 ms |
10976 KB |
Output is correct |
22 |
Correct |
118 ms |
10932 KB |
Output is correct |
23 |
Correct |
102 ms |
10884 KB |
Output is correct |
24 |
Correct |
104 ms |
10820 KB |
Output is correct |