#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
const int LIM=1<<20;
int T[LIM], ans[LIM], n, q;
pair<ll,int>pyt[LIM];
void solve(int l, int r, ll k, int a, int b) {
if(l==r) {
while(a<=b) {
ans[pyt[a].nd]=T[l];
++a;
}
return;
}
int x=a;
while(x<=b && (pyt[x].st/k)%3==0) ++x;
if(x>a) solve(l, (l+r)/2, k/3, a, x-1);
int y=x;
while(y<=b && (pyt[y].st/k)%3==1) ++y;
if(y>x) solve((l+r)/2+1, r, k/3, x, y-1);
if(y<=b) {
rep(i, (r-l+1)/2) T[l+i]+=T[(l+r)/2+1+i];
solve(l, (l+r)/2, k/3, y, b);
rep(i, (r-l+1)/2) T[l+i]-=T[(l+r)/2+1+i];
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
string s;
cin >> n >> q >> s;
ll k=1;
rep(i, n-1) k*=3;
n=1<<n;
rep(i, n) T[i]=s[i]-'0';
rep(i, q) {
string a;
cin >> a;
for(auto j : a) {
pyt[i].st*=3;
if(j=='?') pyt[i].st+=2;
else pyt[i].st+=j-'0';
}
pyt[i].nd=i;
}
sort(pyt, pyt+q);
solve(0, n-1, k, 0, q-1);
rep(i, q) cout << ans[i] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
372 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
288 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
372 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
288 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
332 ms |
26148 KB |
Output is correct |
12 |
Correct |
335 ms |
25864 KB |
Output is correct |
13 |
Correct |
317 ms |
25120 KB |
Output is correct |
14 |
Correct |
338 ms |
25192 KB |
Output is correct |
15 |
Correct |
316 ms |
26156 KB |
Output is correct |
16 |
Correct |
346 ms |
25296 KB |
Output is correct |
17 |
Correct |
330 ms |
25388 KB |
Output is correct |
18 |
Correct |
181 ms |
27116 KB |
Output is correct |
19 |
Correct |
339 ms |
24116 KB |
Output is correct |
20 |
Correct |
349 ms |
25888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
372 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
288 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
332 ms |
26148 KB |
Output is correct |
12 |
Correct |
335 ms |
25864 KB |
Output is correct |
13 |
Correct |
317 ms |
25120 KB |
Output is correct |
14 |
Correct |
338 ms |
25192 KB |
Output is correct |
15 |
Correct |
316 ms |
26156 KB |
Output is correct |
16 |
Correct |
346 ms |
25296 KB |
Output is correct |
17 |
Correct |
330 ms |
25388 KB |
Output is correct |
18 |
Correct |
181 ms |
27116 KB |
Output is correct |
19 |
Correct |
339 ms |
24116 KB |
Output is correct |
20 |
Correct |
349 ms |
25888 KB |
Output is correct |
21 |
Correct |
353 ms |
26132 KB |
Output is correct |
22 |
Correct |
353 ms |
26388 KB |
Output is correct |
23 |
Correct |
349 ms |
25524 KB |
Output is correct |
24 |
Correct |
360 ms |
25156 KB |
Output is correct |
25 |
Correct |
340 ms |
27152 KB |
Output is correct |
26 |
Correct |
372 ms |
25680 KB |
Output is correct |
27 |
Correct |
369 ms |
25412 KB |
Output is correct |
28 |
Correct |
207 ms |
27944 KB |
Output is correct |
29 |
Correct |
372 ms |
23744 KB |
Output is correct |
30 |
Correct |
355 ms |
25988 KB |
Output is correct |
31 |
Correct |
357 ms |
25848 KB |
Output is correct |
32 |
Correct |
372 ms |
25604 KB |
Output is correct |
33 |
Correct |
343 ms |
24344 KB |
Output is correct |
34 |
Correct |
389 ms |
24332 KB |
Output is correct |
35 |
Correct |
367 ms |
24260 KB |
Output is correct |
36 |
Correct |
264 ms |
22456 KB |
Output is correct |
37 |
Correct |
349 ms |
24388 KB |
Output is correct |
38 |
Correct |
335 ms |
22360 KB |
Output is correct |
39 |
Correct |
365 ms |
23644 KB |
Output is correct |
40 |
Correct |
352 ms |
23404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
372 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
288 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
39 ms |
7268 KB |
Output is correct |
12 |
Correct |
39 ms |
7244 KB |
Output is correct |
13 |
Correct |
82 ms |
7200 KB |
Output is correct |
14 |
Correct |
120 ms |
7200 KB |
Output is correct |
15 |
Correct |
82 ms |
7332 KB |
Output is correct |
16 |
Correct |
101 ms |
7280 KB |
Output is correct |
17 |
Correct |
129 ms |
7204 KB |
Output is correct |
18 |
Correct |
23 ms |
7400 KB |
Output is correct |
19 |
Correct |
27 ms |
7140 KB |
Output is correct |
20 |
Correct |
39 ms |
7324 KB |
Output is correct |
21 |
Correct |
100 ms |
7300 KB |
Output is correct |
22 |
Correct |
100 ms |
7196 KB |
Output is correct |
23 |
Correct |
59 ms |
7140 KB |
Output is correct |
24 |
Correct |
93 ms |
7268 KB |
Output is correct |
25 |
Correct |
99 ms |
7200 KB |
Output is correct |
26 |
Correct |
23 ms |
7148 KB |
Output is correct |
27 |
Correct |
37 ms |
7268 KB |
Output is correct |
28 |
Correct |
27 ms |
7084 KB |
Output is correct |
29 |
Correct |
81 ms |
7032 KB |
Output is correct |
30 |
Correct |
92 ms |
7072 KB |
Output is correct |
31 |
Correct |
57 ms |
7088 KB |
Output is correct |
32 |
Correct |
103 ms |
7048 KB |
Output is correct |
33 |
Correct |
105 ms |
7112 KB |
Output is correct |
34 |
Correct |
20 ms |
7004 KB |
Output is correct |
35 |
Correct |
91 ms |
7076 KB |
Output is correct |
36 |
Correct |
92 ms |
7068 KB |
Output is correct |
37 |
Correct |
92 ms |
7136 KB |
Output is correct |
38 |
Correct |
89 ms |
7144 KB |
Output is correct |
39 |
Correct |
89 ms |
7140 KB |
Output is correct |
40 |
Correct |
89 ms |
6996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
372 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
288 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
332 ms |
26148 KB |
Output is correct |
12 |
Correct |
335 ms |
25864 KB |
Output is correct |
13 |
Correct |
317 ms |
25120 KB |
Output is correct |
14 |
Correct |
338 ms |
25192 KB |
Output is correct |
15 |
Correct |
316 ms |
26156 KB |
Output is correct |
16 |
Correct |
346 ms |
25296 KB |
Output is correct |
17 |
Correct |
330 ms |
25388 KB |
Output is correct |
18 |
Correct |
181 ms |
27116 KB |
Output is correct |
19 |
Correct |
339 ms |
24116 KB |
Output is correct |
20 |
Correct |
349 ms |
25888 KB |
Output is correct |
21 |
Correct |
353 ms |
26132 KB |
Output is correct |
22 |
Correct |
353 ms |
26388 KB |
Output is correct |
23 |
Correct |
349 ms |
25524 KB |
Output is correct |
24 |
Correct |
360 ms |
25156 KB |
Output is correct |
25 |
Correct |
340 ms |
27152 KB |
Output is correct |
26 |
Correct |
372 ms |
25680 KB |
Output is correct |
27 |
Correct |
369 ms |
25412 KB |
Output is correct |
28 |
Correct |
207 ms |
27944 KB |
Output is correct |
29 |
Correct |
372 ms |
23744 KB |
Output is correct |
30 |
Correct |
355 ms |
25988 KB |
Output is correct |
31 |
Correct |
357 ms |
25848 KB |
Output is correct |
32 |
Correct |
372 ms |
25604 KB |
Output is correct |
33 |
Correct |
343 ms |
24344 KB |
Output is correct |
34 |
Correct |
389 ms |
24332 KB |
Output is correct |
35 |
Correct |
367 ms |
24260 KB |
Output is correct |
36 |
Correct |
264 ms |
22456 KB |
Output is correct |
37 |
Correct |
349 ms |
24388 KB |
Output is correct |
38 |
Correct |
335 ms |
22360 KB |
Output is correct |
39 |
Correct |
365 ms |
23644 KB |
Output is correct |
40 |
Correct |
352 ms |
23404 KB |
Output is correct |
41 |
Correct |
39 ms |
7268 KB |
Output is correct |
42 |
Correct |
39 ms |
7244 KB |
Output is correct |
43 |
Correct |
82 ms |
7200 KB |
Output is correct |
44 |
Correct |
120 ms |
7200 KB |
Output is correct |
45 |
Correct |
82 ms |
7332 KB |
Output is correct |
46 |
Correct |
101 ms |
7280 KB |
Output is correct |
47 |
Correct |
129 ms |
7204 KB |
Output is correct |
48 |
Correct |
23 ms |
7400 KB |
Output is correct |
49 |
Correct |
27 ms |
7140 KB |
Output is correct |
50 |
Correct |
39 ms |
7324 KB |
Output is correct |
51 |
Correct |
100 ms |
7300 KB |
Output is correct |
52 |
Correct |
100 ms |
7196 KB |
Output is correct |
53 |
Correct |
59 ms |
7140 KB |
Output is correct |
54 |
Correct |
93 ms |
7268 KB |
Output is correct |
55 |
Correct |
99 ms |
7200 KB |
Output is correct |
56 |
Correct |
23 ms |
7148 KB |
Output is correct |
57 |
Correct |
37 ms |
7268 KB |
Output is correct |
58 |
Correct |
27 ms |
7084 KB |
Output is correct |
59 |
Correct |
81 ms |
7032 KB |
Output is correct |
60 |
Correct |
92 ms |
7072 KB |
Output is correct |
61 |
Correct |
57 ms |
7088 KB |
Output is correct |
62 |
Correct |
103 ms |
7048 KB |
Output is correct |
63 |
Correct |
105 ms |
7112 KB |
Output is correct |
64 |
Correct |
20 ms |
7004 KB |
Output is correct |
65 |
Correct |
91 ms |
7076 KB |
Output is correct |
66 |
Correct |
92 ms |
7068 KB |
Output is correct |
67 |
Correct |
92 ms |
7136 KB |
Output is correct |
68 |
Correct |
89 ms |
7144 KB |
Output is correct |
69 |
Correct |
89 ms |
7140 KB |
Output is correct |
70 |
Correct |
89 ms |
6996 KB |
Output is correct |
71 |
Correct |
494 ms |
51616 KB |
Output is correct |
72 |
Correct |
488 ms |
51904 KB |
Output is correct |
73 |
Correct |
706 ms |
50476 KB |
Output is correct |
74 |
Correct |
788 ms |
50640 KB |
Output is correct |
75 |
Correct |
639 ms |
52708 KB |
Output is correct |
76 |
Correct |
827 ms |
50948 KB |
Output is correct |
77 |
Correct |
840 ms |
50816 KB |
Output is correct |
78 |
Correct |
252 ms |
54668 KB |
Output is correct |
79 |
Correct |
434 ms |
48808 KB |
Output is correct |
80 |
Correct |
494 ms |
51848 KB |
Output is correct |
81 |
Correct |
781 ms |
51736 KB |
Output is correct |
82 |
Correct |
785 ms |
50748 KB |
Output is correct |
83 |
Correct |
579 ms |
49888 KB |
Output is correct |
84 |
Correct |
785 ms |
50660 KB |
Output is correct |
85 |
Correct |
830 ms |
50804 KB |
Output is correct |
86 |
Correct |
380 ms |
48556 KB |
Output is correct |
87 |
Correct |
487 ms |
51508 KB |
Output is correct |
88 |
Correct |
449 ms |
48516 KB |
Output is correct |
89 |
Correct |
716 ms |
50088 KB |
Output is correct |
90 |
Correct |
768 ms |
50708 KB |
Output is correct |
91 |
Correct |
566 ms |
49972 KB |
Output is correct |
92 |
Correct |
809 ms |
50888 KB |
Output is correct |
93 |
Correct |
825 ms |
50820 KB |
Output is correct |
94 |
Correct |
341 ms |
48572 KB |
Output is correct |
95 |
Correct |
742 ms |
50688 KB |
Output is correct |
96 |
Correct |
748 ms |
50628 KB |
Output is correct |
97 |
Correct |
737 ms |
50708 KB |
Output is correct |
98 |
Correct |
753 ms |
50700 KB |
Output is correct |
99 |
Correct |
740 ms |
50628 KB |
Output is correct |
100 |
Correct |
738 ms |
50844 KB |
Output is correct |