#include <bits/stdc++.h>
#define int long long
#define sz(a) (int)a.size()
#define all(x) (x).begin(), (x).end()
using namespace std;
struct FenwickTree{
vector<int> bit;
int n;
FenwickTree(int vn){
this->n=vn;
bit.resize(vn,0);
}
FenwickTree(vector<int> const &a) : FenwickTree(sz(a)) {
for (int i = 0; i < sz(a); i++) add(i, 0, a[i]);
}
int sum(int r){
int ret=0;
for (; r>=0; r=(r&(r+1))-1) ret=ret^bit[r];
return ret;
}
int sum(int l, int r){
return sum(l-1)^sum(r);
}
void add(int r, int prev, int delta){
for (; r<n; r=(r|(r+1))) {
bit[r]=bit[r]^prev;
bit[r]=bit[r]^delta;
}
}
};
signed main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n,q; cin >> n>>q;
vector<int> uneven(n/2);
vector<int> even((n+1)/2);
for (int i = 0; i < n; i++)
{
int a; cin >> a;
if(i%2) uneven[i/2]=a;
else even[i/2]=a;
}
FenwickTree evn(even);
FenwickTree unevn(uneven);
for (int i = 0; i < q; i++)
{
int t,a,b; cin >> t >> a >> b;
if(t==1){
a--;
if(a%2==0) {
evn.add(a/2, even[a/2], b);
even[a/2]=b;
}
else {
unevn.add(a/2, uneven[a/2], b);
uneven[a/2]=b;
}
}else{
a--; b--;
if((b-a+1)%2==0) cout << "0\n";
else {
if(a%2==0) cout << evn.sum(a/2, b/2) << "\n";
else cout << unevn.sum(a/2, b/2) << "\n";
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
596 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
0 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
4588 KB |
Output is correct |
2 |
Correct |
64 ms |
4700 KB |
Output is correct |
3 |
Correct |
72 ms |
4684 KB |
Output is correct |
4 |
Correct |
59 ms |
4692 KB |
Output is correct |
5 |
Correct |
59 ms |
4684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
0 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
64 ms |
4588 KB |
Output is correct |
16 |
Correct |
64 ms |
4700 KB |
Output is correct |
17 |
Correct |
72 ms |
4684 KB |
Output is correct |
18 |
Correct |
59 ms |
4692 KB |
Output is correct |
19 |
Correct |
59 ms |
4684 KB |
Output is correct |
20 |
Correct |
62 ms |
9124 KB |
Output is correct |
21 |
Correct |
80 ms |
9200 KB |
Output is correct |
22 |
Correct |
68 ms |
9328 KB |
Output is correct |
23 |
Correct |
62 ms |
9044 KB |
Output is correct |
24 |
Correct |
60 ms |
9044 KB |
Output is correct |