-
Notifications
You must be signed in to change notification settings - Fork 0
/
D.cpp
86 lines (67 loc) · 1.69 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll const inf = 1e18;
ll const maxn = 1e6+5;
ll const mod = 1e9+7;
long long binpow(long long a, long long b) {
if (b == 0)
return 1;
long long res = binpow(a, b / 2);
if (b % 2)
return res * res * a;
else
return res * res;
}
// code begins here
vector<ll> arr(maxn), t(maxn);
void build( ll v, ll tl, ll tr, ll decide) {
if (tl == tr) {
t[v] = arr[tl];
} else {
ll tm = (tl + tr) / 2;
build( v*2, tl, tm, !decide );
build( v*2+1, tm+1, tr, !decide );
if(decide)
t[v] = t[v*2] | t[v*2+1];
else
t[v] = t[v*2] ^ t[v*2+1];
}
}
void update( ll v, ll tl, ll tr, ll pos, ll new_val, ll decide) {
if (tl == tr) {
t[v] = new_val;
} else {
ll tm = (tl + tr) / 2;
if (pos <= tm)
update(v*2, tl, tm, pos, new_val, !decide);
else
update(v*2+1, tm+1, tr, pos, new_val, !decide);
if(decide)
t[v] = t[v*2] | t[v*2+1];
else
t[v] = t[v*2] ^ t[v*2+1];
}
}
int main(){
fast;
ll n,m;
cin>>n>>m;
ll total = binpow(2,n);
for(ll i=0;i<total;i++)
cin>>arr[i];
build(1, 0, total-1, n%2 );
while(m--){
ll p,b;
cin>>p>>b;
update(1, 0, total-1, p-1, b, n%2);
// for(ll i=1;i<8;i++)
// cout<<t[i]<<" ";
// cout<<endl;
cout<<t[1]<<endl;
}
return 0;
}