#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef vector<int> vi;
struct segtree {
int len;
vi a;
void make(int n) {
len = 1;
while (len < n) len *= 2;
a.resize(2 * len, 0);
}
void update(int ind, int val) {
ind += len;
a[ind] = val;
ind /= 2;
while (ind > 0) {
a[ind] = a[2 * ind + 1] ^ a[2 * ind];
ind /= 2;
}
}
int query(int l, int r) {
l += len, r += len;
int ans = 0;
while (r >= l) {
if (l % 2 == 1) ans ^= a[l++];
if (r % 2 == 0) ans ^= a[r--];
l /= 2, r /= 2;
}
return ans;
}
};
int main()
{
int n, q, a_1, type, b_1, b_2;
segtree seg1, seg2;
cin >> n >> q;
seg1.make(n);
seg2.make(n);
for (int i = 0; i < n; i++) {
cin >> a_1;
if (i % 2) seg1.update(i, a_1);
else seg2.update(i, a_1);
}
for (int i = 0; i < q; i++) {
cin >> type >> b_1 >> b_2;
if (type == 1) {
if ((b_1-1) % 2) seg1.update(b_1 - 1, b_2);
else seg2.update(b_1 - 1, b_2);
}
if (type == 2) {
if ((b_2 - b_1 - 1) % 2) {
if ((b_1 - 1) % 2) cout << seg1.query(b_1 - 1, b_2 - 1) << "\n";
else cout << seg2.query(b_1 - 1, b_2 - 1) << "\n";
}
else cout << 0 << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
272 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
288 KB |
Output is correct |
2 |
Correct |
2 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
296 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
272 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
292 KB |
Output is correct |
6 |
Correct |
2 ms |
288 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
2 ms |
296 KB |
Output is correct |
10 |
Correct |
2 ms |
204 KB |
Output is correct |
11 |
Correct |
12 ms |
432 KB |
Output is correct |
12 |
Correct |
11 ms |
460 KB |
Output is correct |
13 |
Correct |
15 ms |
460 KB |
Output is correct |
14 |
Correct |
14 ms |
528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
625 ms |
10516 KB |
Output is correct |
2 |
Correct |
614 ms |
10320 KB |
Output is correct |
3 |
Correct |
617 ms |
10400 KB |
Output is correct |
4 |
Correct |
662 ms |
9992 KB |
Output is correct |
5 |
Correct |
598 ms |
10080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
272 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
292 KB |
Output is correct |
6 |
Correct |
2 ms |
288 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
2 ms |
296 KB |
Output is correct |
10 |
Correct |
2 ms |
204 KB |
Output is correct |
11 |
Correct |
12 ms |
432 KB |
Output is correct |
12 |
Correct |
11 ms |
460 KB |
Output is correct |
13 |
Correct |
15 ms |
460 KB |
Output is correct |
14 |
Correct |
14 ms |
528 KB |
Output is correct |
15 |
Correct |
625 ms |
10516 KB |
Output is correct |
16 |
Correct |
614 ms |
10320 KB |
Output is correct |
17 |
Correct |
617 ms |
10400 KB |
Output is correct |
18 |
Correct |
662 ms |
9992 KB |
Output is correct |
19 |
Correct |
598 ms |
10080 KB |
Output is correct |
20 |
Correct |
547 ms |
10104 KB |
Output is correct |
21 |
Correct |
468 ms |
10048 KB |
Output is correct |
22 |
Correct |
473 ms |
10136 KB |
Output is correct |
23 |
Correct |
575 ms |
10056 KB |
Output is correct |
24 |
Correct |
591 ms |
10020 KB |
Output is correct |