#include "bits/stdc++.h"
#define N (int)1e5
std::vector <int> t1, t2;
int k ;
void update1(const int pos, const int val, int vl = 0, int vr = k - 1, int v = 0) {
if(vl == vr) {
t1[v] = val;
return;
}
int vm = (vl + vr) / 2;
if(pos <= vm) update1(pos, val, vl, vm, 2*v+1);
else update1(pos, val, vm+1, vr, 2*v+2);
t1[v] = t1[2*v+1] ^ t1[2*v+2];
}
void update2(const int pos, const int val, int vl = 0, int vr = k - 1, int v = 0) {
if(vl == vr) {
t2[v] = val;
return;
}
int vm = (vl + vr) / 2;
if(pos <= vm) update2(pos, val, vl, vm, 2*v+1);
else update2(pos, val, vm+1, vr, 2*v+2);
t2[v] = t2[2*v+1] ^ t2[2*v+2];
}
int get1(const int l, const int r, int vl = 0, int vr = k - 1, int v = 0) {
if(l > vr || vl > r) return 0;
if(l <= vl && vr <= r) return t1[v];
int vm = (vl + vr ) / 2;
return get1(l, r, vl, vm, 2*v+1) ^ get1(l, r, vm+1, vr, 2*v+2);
}
int get2(const int l, const int r, int vl = 0, int vr = k - 1, int v = 0) {
if(l > vr || vl > r) return 0;
if(l <= vl && vr <= r) return t2[v];
int vm = (vl + vr ) / 2;
return get2(l, r, vl, vm, 2*v+1) ^ get2(l, r, vm+1, vr, 2*v+2);
}
signed main () {
int n, q;
scanf("%d%d", &n, &q);
k= 1;
while(k < n) k <<= 1;
t1.resize(2*k-1,0);
t2.resize(2*k-1.0);
int a[n];
for(int i = 0; i < n; i ++) scanf("%d", &a[i]);
for(int i = 0; i < n; i ++) {
if(i % 2== 0) update1(i, a[i]);
else update2(i, a[i]);
}
while(q --) {
int type;
scanf("%d", &type);
if(type == 1) {
int i, x;
scanf("%d%d", &i, &x);
i --;
if(i % 2== 0) update1(i, x);
else update2(i, x);
}else {
int l, r;
scanf("%d%d", &l, &r);
l --;
if((r-l) % 2 == 0) {
printf("0\n");
continue;
}
int ans = 0;
if(l % 2 == 0) {
ans = get1(l, r-1);
}else {
ans = get2(l, r-1);
}
printf("%d\n", ans);
}
}
return 0;
}
Compilation message
xoranges.cpp: In function 'int main()':
xoranges.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | scanf("%d%d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~
xoranges.cpp:52:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | for(int i = 0; i < n; i ++) scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
xoranges.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | scanf("%d", &type);
| ~~~~~^~~~~~~~~~~~~
xoranges.cpp:62:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | scanf("%d%d", &i, &x);
| ~~~~~^~~~~~~~~~~~~~~~
xoranges.cpp:68:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | scanf("%d%d", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
340 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 |
308 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 |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
146 ms |
11176 KB |
Output is correct |
2 |
Correct |
153 ms |
11180 KB |
Output is correct |
3 |
Correct |
155 ms |
11212 KB |
Output is correct |
4 |
Correct |
134 ms |
10792 KB |
Output is correct |
5 |
Correct |
135 ms |
10808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
146 ms |
11176 KB |
Output is correct |
16 |
Correct |
153 ms |
11180 KB |
Output is correct |
17 |
Correct |
155 ms |
11212 KB |
Output is correct |
18 |
Correct |
134 ms |
10792 KB |
Output is correct |
19 |
Correct |
135 ms |
10808 KB |
Output is correct |
20 |
Correct |
154 ms |
10924 KB |
Output is correct |
21 |
Correct |
143 ms |
10936 KB |
Output is correct |
22 |
Correct |
151 ms |
10924 KB |
Output is correct |
23 |
Correct |
138 ms |
10756 KB |
Output is correct |
24 |
Correct |
142 ms |
10864 KB |
Output is correct |