#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
using namespace std;
const int N = 2e5 + 5;
int n, q, a[N], type, l, r, t[2][N * 4];
void build (int v = 1, int tl = 1, int tr = n) {
if (tl == tr) {
t[tl & 1][v] = a[tl];
} else {
int tm = (tl + tr) >> 1;
build(v + v, tl, tm);
build(v + v + 1, tm + 1, tr);
t[0][v] = t[0][v + v] ^ t[0][v + v + 1];
t[1][v] = t[1][v + v] ^ t[1][v + v + 1];
}
}
void update (int pos, int val, int v = 1, int tl = 1, int tr = n) {
if (tl == tr) {
t[tl & 1][v] = val;
} else {
int tm = (tl + tr) >> 1;
if (pos <= tm)
update(pos, val, v + v, tl, tm);
else
update(pos, val, v + v + 1, tm + 1, tr);
t[0][v] = t[0][v + v] ^ t[0][v + v + 1];
t[1][v] = t[1][v + v] ^ t[1][v + v + 1];
}
}
int get (int l, int r, int v = 1, int tl = 1, int tr = n) {
if (l > tr || tl > r)
return 0;
if (l <= tl && tr <= r)
return t[l & 1][v];
int tm = (tl + tr) >> 1;
return get(l, r, v + v, tl, tm) ^ get(l, r, v + v + 1, tm + 1, tr);
}
main(){
cin >> n >> q;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
build();
while (q--) {
cin >> type >> l >> r;
if (type == 1) {
update(l, r);
} else {
if ((r - l + 1) & 1) {
printf("%d\n", get(l, r));
} else {
puts("0");
}
}
}
}
Compilation message
xoranges.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
50 | main(){
| ^~~~
xoranges.cpp: In function 'int main()':
xoranges.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
320 KB |
Output is correct |
5 |
Correct |
2 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
320 KB |
Output is correct |
10 |
Correct |
2 ms |
316 KB |
Output is correct |
11 |
Correct |
11 ms |
596 KB |
Output is correct |
12 |
Correct |
9 ms |
596 KB |
Output is correct |
13 |
Correct |
11 ms |
596 KB |
Output is correct |
14 |
Correct |
11 ms |
568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
640 ms |
11128 KB |
Output is correct |
2 |
Correct |
480 ms |
11156 KB |
Output is correct |
3 |
Correct |
494 ms |
11188 KB |
Output is correct |
4 |
Correct |
456 ms |
10856 KB |
Output is correct |
5 |
Correct |
453 ms |
10844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
320 KB |
Output is correct |
10 |
Correct |
2 ms |
316 KB |
Output is correct |
11 |
Correct |
11 ms |
596 KB |
Output is correct |
12 |
Correct |
9 ms |
596 KB |
Output is correct |
13 |
Correct |
11 ms |
596 KB |
Output is correct |
14 |
Correct |
11 ms |
568 KB |
Output is correct |
15 |
Correct |
640 ms |
11128 KB |
Output is correct |
16 |
Correct |
480 ms |
11156 KB |
Output is correct |
17 |
Correct |
494 ms |
11188 KB |
Output is correct |
18 |
Correct |
456 ms |
10856 KB |
Output is correct |
19 |
Correct |
453 ms |
10844 KB |
Output is correct |
20 |
Correct |
376 ms |
10952 KB |
Output is correct |
21 |
Correct |
366 ms |
10848 KB |
Output is correct |
22 |
Correct |
354 ms |
10848 KB |
Output is correct |
23 |
Correct |
423 ms |
10928 KB |
Output is correct |
24 |
Correct |
447 ms |
10828 KB |
Output is correct |