-
Notifications
You must be signed in to change notification settings - Fork 1
/
D.cpp
72 lines (57 loc) · 1.5 KB
/
D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll ara[200009], tree[600009];
void build(ll lo, ll hi, ll state, ll node)
{
if(lo == hi) {
tree[node] = ara[lo];
// state = 1;
return;
}
ll mid = (lo + hi) / 2;
build(lo, mid, state ^ 1, 2 * node);
build(mid + 1, hi, state ^ 1, 2 * node + 1);
if(state)
tree[node] = tree[2 * node] | tree[2 * node + 1];
else
tree[node] = tree[2 * node] ^ tree[2 * node + 1];
}
void update(ll lo, ll hi, ll indx, ll val, ll state, ll node)
{
if(lo > indx || hi < indx)
return;
if(lo == hi) {
tree[node] = val;
// state = 1;
return;
}
ll mid = (lo + hi) / 2;
update(lo, mid, indx, val, state ^ 1, 2 * node);
update(mid + 1, hi, indx, val, state ^ 1, 2 * node + 1);
if(state) {
tree[node] = tree[2 * node] | tree[2 * node + 1];
}
else
tree[node] = tree[2 * node] ^ tree[2 * node + 1];
//cout << tree[node] << " " << tree[2 * node] << " " << tree[2 * node + 1] << " " << state << " " << lo << " " << hi << endl;
}
int main()
{
ll n, q;
cin >> n >> q;
ll pw = 1 << n;
for(ll i = 1; i <= pw; i++)
scanf("%lld", &ara[i]);
ll state = 1;
if(n % 2 == 0)
state = 0;
build(1, pw, state, 1);
while(q--) {
ll indx, num;
scanf("%lld %lld", &indx, &num);
update(1, pw, indx, num, state, 1);
printf("%lld\n", tree[1]);
}
return 0;
}