#include <bits/stdc++.h>
using namespace std;
class SegmentTree
{
private:
vector<int> st;
int N;
int l(int x) { return (x << 1); }
int r(int x) { return (x << 1) + 1; }
void update(int pos, int val, int L, int R, int x)
{
if (pos < L || pos > R)
return;
if (L == R)
{
st[x] = val;
}
else
{
int m = (L + R) / 2;
update(pos, val, L, m, l(x));
update(pos, val, m + 1, R, r(x));
st[x] = st[l(x)] ^ st[r(x)];
}
}
int RSQ(int L, int R, int a, int b, int x)
{
if (L > b || R < a)
return 0;
if (L >= a && R <= b)
return st[x];
int m = (L + R) / 2;
return RSQ(L, m, a, b, l(x)) ^
RSQ(m + 1, R, a, b, r(x));
}
public:
SegmentTree(int x)
{
N = pow(2, ceil(log2(x)));
st.assign(3 * N, 0);
}
void update(int pos, int val)
{
update(pos, val, 0, N - 1, 1);
}
int RSQ(int a, int b)
{
return RSQ(0, N - 1, a, b, 1);
}
};
int main()
{
int N, Q;
cin >> N >> Q;
SegmentTree odd(N), even(N);
for (int i = 0; i < N; i++)
{
int x;
cin >> x;
if (i % 2)
odd.update(i, x);
else
even.update(i, x);
}
for (int i = 0; i < Q; i++)
{
int type;
cin >> type;
if (type == 1)
{
int x, val;
cin >> x >> val;
x--;
if (x % 2)
odd.update(x, val);
else
even.update(x, val);
}
else
{
int a, b;
cin >> a >> b;
a--, b--;
if ((b - a) % 2 == 1)
cout << 0 << '\n';
else
{
if (a % 2)
cout << odd.RSQ(a, b) << '\n';
else
cout << even.RSQ(a, b) << '\n';
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
9 ms |
600 KB |
Output is correct |
12 |
Correct |
8 ms |
600 KB |
Output is correct |
13 |
Correct |
12 ms |
600 KB |
Output is correct |
14 |
Correct |
11 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
467 ms |
12588 KB |
Output is correct |
2 |
Correct |
466 ms |
12404 KB |
Output is correct |
3 |
Correct |
462 ms |
12496 KB |
Output is correct |
4 |
Correct |
454 ms |
12168 KB |
Output is correct |
5 |
Correct |
451 ms |
12368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
9 ms |
600 KB |
Output is correct |
12 |
Correct |
8 ms |
600 KB |
Output is correct |
13 |
Correct |
12 ms |
600 KB |
Output is correct |
14 |
Correct |
11 ms |
600 KB |
Output is correct |
15 |
Correct |
467 ms |
12588 KB |
Output is correct |
16 |
Correct |
466 ms |
12404 KB |
Output is correct |
17 |
Correct |
462 ms |
12496 KB |
Output is correct |
18 |
Correct |
454 ms |
12168 KB |
Output is correct |
19 |
Correct |
451 ms |
12368 KB |
Output is correct |
20 |
Correct |
383 ms |
12376 KB |
Output is correct |
21 |
Correct |
366 ms |
12540 KB |
Output is correct |
22 |
Correct |
370 ms |
12204 KB |
Output is correct |
23 |
Correct |
441 ms |
12216 KB |
Output is correct |
24 |
Correct |
435 ms |
12164 KB |
Output is correct |