# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
930180 |
2024-02-18T20:53:48 Z |
AmrT |
XORanges (eJOI19_xoranges) |
C++14 |
|
343 ms |
17112 KB |
#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--;
if((r - l + 1) % 2 == 0)
cout << 0 << endl;
else
cout << a[(l & 1)].get(l, r) << endl;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
5 ms |
860 KB |
Output is correct |
12 |
Correct |
5 ms |
876 KB |
Output is correct |
13 |
Correct |
8 ms |
1116 KB |
Output is correct |
14 |
Correct |
8 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
318 ms |
15040 KB |
Output is correct |
2 |
Correct |
340 ms |
15056 KB |
Output is correct |
3 |
Correct |
332 ms |
15040 KB |
Output is correct |
4 |
Correct |
343 ms |
15028 KB |
Output is correct |
5 |
Correct |
299 ms |
15032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
5 ms |
860 KB |
Output is correct |
12 |
Correct |
5 ms |
876 KB |
Output is correct |
13 |
Correct |
8 ms |
1116 KB |
Output is correct |
14 |
Correct |
8 ms |
860 KB |
Output is correct |
15 |
Correct |
318 ms |
15040 KB |
Output is correct |
16 |
Correct |
340 ms |
15056 KB |
Output is correct |
17 |
Correct |
332 ms |
15040 KB |
Output is correct |
18 |
Correct |
343 ms |
15028 KB |
Output is correct |
19 |
Correct |
299 ms |
15032 KB |
Output is correct |
20 |
Correct |
216 ms |
17112 KB |
Output is correct |
21 |
Correct |
190 ms |
17080 KB |
Output is correct |
22 |
Correct |
188 ms |
17076 KB |
Output is correct |
23 |
Correct |
302 ms |
17088 KB |
Output is correct |
24 |
Correct |
295 ms |
17084 KB |
Output is correct |