#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 querry(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 %= querry(2*N, l, m, i, ql, min(qr, m));
if(qr > m)
answer %= querry(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", querry(1, 1, N / 2, 1, b / 2, c / 2));
else
printf("%d\n", querry(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 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
133 ms |
8276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |