#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <stack>
using namespace std;
using ll = long long;
vector <int> v, anc;
int s[800020];
void build(int p, int lp, int rp)
{
if (lp == rp)
{
s[p] = v[lp];
return;
}
int m = (lp + rp) / 2;
build(p * 2, lp, m);
build(p * 2 + 1, m + 1, rp);
s[p] = s[p * 2] + s[p * 2 + 1];
}
int getxor(int p, int lp, int rp, int l, int r)
{
if (l > r)
return 0;
if (lp == l && rp == r)
return s[p];
int m = (lp + rp) / 2;
return getxor(p * 2, lp, m, l, min(m, r)) ^ getxor(p * 2 + 1, m + 1, rp, max(m, l), r);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q, i, j, x, ans = 0, c,y;
cin >> n >> q;
for ( i = 0; i < n; i++)
{
cin >> x;
v.push_back(x);
}
if (n <= 5000 && q <= 5000)
{
ans = 0;
int g = 0;
for (i = 0; i < q; i++)
{
cin >> c >> x >> y;
x--; y--;
if (c == 1)
{
v[x] = y + 1;
}
else
{
int f = 0;
for (j = x; j <= y; j++)
{
if (((j - x + 1) * (y - j + 1)) % 2)
f = f ^ v[j];
}
ans = f;
g = 1;
cout << ans << '\n';
}
}
}
else
{
build(1, 0, n - 1);
for ( i = 0; i < q; i++)
{
cin >> c >> x >> y;
x--; y--;
cout << getxor(1, 0, n - 1, x, y) << endl;
}
}
return 0;
}
Compilation message
xoranges.cpp: In function 'int main()':
xoranges.cpp:53:13: warning: variable 'g' set but not used [-Wunused-but-set-variable]
53 | int g = 0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
8 ms |
332 KB |
Output is correct |
12 |
Correct |
9 ms |
588 KB |
Output is correct |
13 |
Correct |
28 ms |
484 KB |
Output is correct |
14 |
Correct |
27 ms |
480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
71 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
8 ms |
332 KB |
Output is correct |
12 |
Correct |
9 ms |
588 KB |
Output is correct |
13 |
Correct |
28 ms |
484 KB |
Output is correct |
14 |
Correct |
27 ms |
480 KB |
Output is correct |
15 |
Runtime error |
71 ms |
65540 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |