#include <iostream>
using namespace std;
int segTree[400005][2];
int oranges[200005];
void init(int N, int l, int r, int i)
{
if(l == r)
{
segTree[N][i] = i == 0 ? oranges[2 * l - 1] : oranges[2 * l];
return;
}
int m = (l + r) / 2;
init(2*N, l, m, i);
init(2*N + 1, m + 1, r, i);
segTree[N][i] = segTree[2*N][i] ^ segTree[2*N + 1][i];
}
void update(int N, int l, int r, int i, int pos, int val)
{
if(l == r)
{
segTree[N][i] = val;
return;
}
int m = (l + r) / 2;
if(pos <= m)
update(2*N, l, m, i, pos, val);
else
update(2*N + 1, m + 1, r, i, pos, val);
segTree[N][i] = segTree[2*N][i] ^ segTree[2*N + 1][i];
}
int query(int N, int l, int r, int i, int ql, int qr)
{
if(l == ql && r == qr)
return segTree[N][i];
int m = (l + r) / 2;
int answer = 0;
if(ql <= m)
answer ^= query(2*N, l, m, i, ql, min(qr, m));
if(qr > m)
answer ^= query(2*N + 1, m + 1, r, i, max(ql, m + 1), qr);
return answer;
}
int main()
{
int N, Q;
scanf("%d %d", &N, &Q);
for(int i = 1; i <= N; i++)
scanf("%d", &oranges[i]);
init(1, 1, (N + 1) / 2, 0);
init(1, 1, N / 2, 1);
int a, b, c;
while(Q--)
{
scanf("%d %d %d", &a, &b, &c);
if(a == 1)
{
if(b % 2 == 0)
update(1, 1, N / 2, 1, b / 2, c);
else
update(1, 1, (N + 1) / 2, 0, (b + 1) / 2, c);
}
else
{
if((c - b + 1) % 2 == 0)
printf("0\n");
else
{
if(b % 2 == 0)
printf("%d\n", query(1, 1, N / 2, 1, b / 2, c / 2));
else
printf("%d\n", query(1, 1, (N + 1) / 2, 0, (b + 1) / 2, (c + 1) / 2));
}
}
}
return 0;
}
Compilation message
xoranges.cpp: In function 'int main()':
xoranges.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | scanf("%d %d", &N, &Q);
| ~~~~~^~~~~~~~~~~~~~~~~
xoranges.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | scanf("%d", &oranges[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~
xoranges.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | scanf("%d %d %d", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2804 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2500 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2804 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2548 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2500 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
4 ms |
2644 KB |
Output is correct |
12 |
Correct |
4 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2616 KB |
Output is correct |
14 |
Correct |
3 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
4348 KB |
Output is correct |
2 |
Correct |
101 ms |
9044 KB |
Output is correct |
3 |
Correct |
100 ms |
9124 KB |
Output is correct |
4 |
Correct |
101 ms |
8788 KB |
Output is correct |
5 |
Correct |
97 ms |
8908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2804 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2548 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2500 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
4 ms |
2644 KB |
Output is correct |
12 |
Correct |
4 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2616 KB |
Output is correct |
14 |
Correct |
3 ms |
2396 KB |
Output is correct |
15 |
Correct |
109 ms |
4348 KB |
Output is correct |
16 |
Correct |
101 ms |
9044 KB |
Output is correct |
17 |
Correct |
100 ms |
9124 KB |
Output is correct |
18 |
Correct |
101 ms |
8788 KB |
Output is correct |
19 |
Correct |
97 ms |
8908 KB |
Output is correct |
20 |
Correct |
108 ms |
8960 KB |
Output is correct |
21 |
Correct |
99 ms |
8792 KB |
Output is correct |
22 |
Correct |
99 ms |
9020 KB |
Output is correct |
23 |
Correct |
96 ms |
8856 KB |
Output is correct |
24 |
Correct |
96 ms |
8848 KB |
Output is correct |