#include <bits/stdc++.h>
#define lop(i,a,b) for(ll i = a; i < b; i++)
#define alop(i,v) for(auto &i: v)
#define in(v) for(auto &i: v) cin >> i;
#define ll long long
//#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(dp, x) memset(dp, x, sizeof(dp))
using namespace std;
const ll mod = 1e9 + 7;
struct segtree{
ll s, e;
vector<ll> tree;
void initialize(ll n, vector<ll> arr){
ll nxt2 = 1 << (__lg(n - 1) + 1);
s = nxt2 - 1, e = nxt2 * 2 - 2;
tree.resize(nxt2 * 2 - 1);
for(int i = 0; i < n; i++)
tree[i + s] = arr[i];
for(int i = s - 1; i >= 0; i--)
tree[i] = tree[i * 2 + 1] ^ tree[i * 2 + 2];
}
void update(ll index, ll value){
index += s;
tree[index] = value;
while(index){
index = (index - !(index % 2) * 2) / 2;
tree[index] = tree[index * 2 + 1] ^ tree[index * 2 + 2];
}
}
ll get(ll x, ll lx, ll rx, ll l, ll r){
if(l <= lx && rx <= r) return tree[x];
else if(rx < l || r < lx) return 0;
else{
ll mid = (lx + rx) / 2;
return get(x * 2 + 1, lx, mid, l, r) ^ get(x * 2 + 2, mid + 1, rx, l, r);
}
}
ll get(ll l, ll r){
return get(0, s, e, l + s, r + s);
}
};
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n, q; cin >> n >> q;
vector<ll> arr[2];
for(int i = 0, x; i < n; i++){
cin >> x;
arr[i % 2].pb(x);
arr[!(i % 2)].pb(0);
}
segtree a[2];
a[0].initialize(n, arr[0]), a[1].initialize(n, arr[1]);
while(q--){
ll t, l, r; cin >> t >> l >> r;
if(t == 1){
l--;
a[l & 1].update(l, r);
}
else{
l--, r--;
cout << a[(l & 1)].get(l, r) << endl;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
351 ms |
15028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |