-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
145 lines (136 loc) · 4.17 KB
/
D.cpp
File metadata and controls
145 lines (136 loc) · 4.17 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>;
using namespace std;
#define ll long long
#define Silver_is_better_than_Gold ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define pb push_back
#define endl '\n'
#define return0 return 0
#define Endl endl
#define ull unsigned long long
#define elif else if
#define test cout<<" We Droped up Here Boss _________________ "<<endl
#define allout(v) for(auto ele : v){cout<<ele<<" ";}cout<<endl
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define txt freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define ld long D
#define vb vector<bool>
#define no {cout<<"NO"<<endl;return ;}
#define yes {cout<<"YES"<<endl;return ;}
#define tests(x) for(int i = 1 ; i<=x;i++)
#define in(v, n) for(int i = 0 ; i<n;i++)cin>>i;
#define outp(v) for(auto ele : v){ cout << ele.first << " " << ele.S << " ";}cout<<endl
const ll mod = 1e9 + 7;
#define inti int i
#define sz(x) ((int) (x).size())
#define dups(divs) divs.erase(unique(divs.begin(), divs.end()), divs.end());
#define fo(i, v, b) for(int i = v ; i<=b;i++)
#define outq(q) queue<int>qq = q;while (qq.size()) { cout << qq.front() << " "; qq.pop();};
#define sttk(x) static_cast<ll>(x)
#define re register
#define intj int j
#define debug cout<<"Output is : ";
#define debug2 cout<<"End of the output______________________"<<endl;
#define sum(v) accumulate(v.begin(),v.end(),0ll)
#define range(i, n) for(int i = 0 ; i <n;i++)
#define point pair<int,int>
#define T int XXX;cin>>XXX;while(XXX--)
#define F first
#define S second
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
template<class A>
istream &operator>>(istream &cin, vector<A> &p) {
for (int i = 0; i < sz(p) - 1; i++)
cin >> p[i];
return cin >> p.back();
}
template<class A>
ostream &operator<<(ostream &cout, vector<A> const &v) {
allout(v);
return cout;
}
ll fastpow(ll base, ll power, ll M) {
if (power == 1) return base;
ll val = fastpow(base, power / 2, M);
return (power % 2 == 0) ? (val * val) % M : (((val * val) % M) * base) % M;
}
//----------------------Code Starts Here-----------------------------//
const int N = 8e5;
int t[N], l[N], r[N];
int n;
string s;
void build(int v, int tl, int tr) {
l[v] = tl;
r[v] = tr;
if (tl == tr) {
t[v] = 1;
return;
}
int tm = (tl + tr) / 2;
build(v * 2, tl, tm);
build(v * 2 + 1, tm + 1, tr);
if (s[n - v] == '?')
t[v] = t[v * 2] + t[v * 2 + 1];
else if (s[n - v] == '1')
t[v] = t[v * 2];
else
t[v] = t[v * 2 + 1];
}
void update(int v, int tl, int tr, char c) {
if (l[v] == tl and r[v] == tr) {
s[n - v] = c;
if (c == '?')
t[v] = t[v * 2] + t[v * 2 + 1];
else if (c == '1')
t[v] = t[v * 2];
else
t[v] = t[(v << 1) + 1];
} else {
int tm = (l[v] + r[v]) / 2;
if (tl < tm)
update(v * 2, tl, tr, c);
else
update(v * 2 + 1, tl, tr, c);
if (s[n - v] == '?')
t[v] = t[v * 2] + t[v * 2 + 1];
else if (s[n - v] == '1')
t[v] = t[v * 2];
else
t[v] = t[v * 2 + 1];
}
}
signed main() {
int k;
cin >> k >> s;
n = (1 << k) - 1;
build(1, 0, n);
int Q;
cin >> Q;
while (Q--) {
int pos;
char c;
cin >> pos >> c;
pos--;
update(1, l[n - pos], r[n - pos], c);
cout << t[1] << endl;
}
}