#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<string,int>pyt[LIM];
void solve(int l, int r, int 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]=='0') ++x;
if(x>a) solve(l, (l+r)/2, k+1, a, x-1);
int y=x;
while(y<=b && pyt[y].st[k]=='1') ++y;
if(y>x) solve((l+r)/2+1, r, k+1, 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+1, 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;
n=1<<n;
rep(i, n) T[i]=s[i]-'0';
rep(i, q) {
cin >> pyt[i].st;
pyt[i].nd=i;
}
sort(pyt, pyt+q);
solve(0, n-1, 0, 0, q-1);
rep(i, q) cout << ans[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
41304 KB |
Output is correct |
2 |
Correct |
20 ms |
41372 KB |
Output is correct |
3 |
Correct |
19 ms |
41388 KB |
Output is correct |
4 |
Correct |
19 ms |
41372 KB |
Output is correct |
5 |
Correct |
20 ms |
41288 KB |
Output is correct |
6 |
Correct |
21 ms |
41404 KB |
Output is correct |
7 |
Correct |
20 ms |
41372 KB |
Output is correct |
8 |
Correct |
19 ms |
41304 KB |
Output is correct |
9 |
Correct |
20 ms |
41388 KB |
Output is correct |
10 |
Correct |
19 ms |
41368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
41304 KB |
Output is correct |
2 |
Correct |
20 ms |
41372 KB |
Output is correct |
3 |
Correct |
19 ms |
41388 KB |
Output is correct |
4 |
Correct |
19 ms |
41372 KB |
Output is correct |
5 |
Correct |
20 ms |
41288 KB |
Output is correct |
6 |
Correct |
21 ms |
41404 KB |
Output is correct |
7 |
Correct |
20 ms |
41372 KB |
Output is correct |
8 |
Correct |
19 ms |
41304 KB |
Output is correct |
9 |
Correct |
20 ms |
41388 KB |
Output is correct |
10 |
Correct |
19 ms |
41368 KB |
Output is correct |
11 |
Correct |
508 ms |
60056 KB |
Output is correct |
12 |
Correct |
519 ms |
59760 KB |
Output is correct |
13 |
Correct |
511 ms |
58920 KB |
Output is correct |
14 |
Correct |
506 ms |
59036 KB |
Output is correct |
15 |
Correct |
505 ms |
59932 KB |
Output is correct |
16 |
Correct |
505 ms |
59152 KB |
Output is correct |
17 |
Correct |
523 ms |
59140 KB |
Output is correct |
18 |
Correct |
371 ms |
60952 KB |
Output is correct |
19 |
Correct |
511 ms |
58128 KB |
Output is correct |
20 |
Correct |
556 ms |
59704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
41304 KB |
Output is correct |
2 |
Correct |
20 ms |
41372 KB |
Output is correct |
3 |
Correct |
19 ms |
41388 KB |
Output is correct |
4 |
Correct |
19 ms |
41372 KB |
Output is correct |
5 |
Correct |
20 ms |
41288 KB |
Output is correct |
6 |
Correct |
21 ms |
41404 KB |
Output is correct |
7 |
Correct |
20 ms |
41372 KB |
Output is correct |
8 |
Correct |
19 ms |
41304 KB |
Output is correct |
9 |
Correct |
20 ms |
41388 KB |
Output is correct |
10 |
Correct |
19 ms |
41368 KB |
Output is correct |
11 |
Correct |
508 ms |
60056 KB |
Output is correct |
12 |
Correct |
519 ms |
59760 KB |
Output is correct |
13 |
Correct |
511 ms |
58920 KB |
Output is correct |
14 |
Correct |
506 ms |
59036 KB |
Output is correct |
15 |
Correct |
505 ms |
59932 KB |
Output is correct |
16 |
Correct |
505 ms |
59152 KB |
Output is correct |
17 |
Correct |
523 ms |
59140 KB |
Output is correct |
18 |
Correct |
371 ms |
60952 KB |
Output is correct |
19 |
Correct |
511 ms |
58128 KB |
Output is correct |
20 |
Correct |
556 ms |
59704 KB |
Output is correct |
21 |
Correct |
529 ms |
63008 KB |
Output is correct |
22 |
Correct |
528 ms |
63176 KB |
Output is correct |
23 |
Correct |
537 ms |
62152 KB |
Output is correct |
24 |
Correct |
510 ms |
62028 KB |
Output is correct |
25 |
Correct |
523 ms |
64032 KB |
Output is correct |
26 |
Correct |
518 ms |
62596 KB |
Output is correct |
27 |
Correct |
532 ms |
62400 KB |
Output is correct |
28 |
Correct |
372 ms |
64964 KB |
Output is correct |
29 |
Correct |
502 ms |
61128 KB |
Output is correct |
30 |
Correct |
512 ms |
63172 KB |
Output is correct |
31 |
Correct |
504 ms |
62928 KB |
Output is correct |
32 |
Correct |
509 ms |
63152 KB |
Output is correct |
33 |
Correct |
514 ms |
61896 KB |
Output is correct |
34 |
Correct |
533 ms |
62020 KB |
Output is correct |
35 |
Correct |
538 ms |
62476 KB |
Output is correct |
36 |
Correct |
404 ms |
61040 KB |
Output is correct |
37 |
Correct |
551 ms |
62932 KB |
Output is correct |
38 |
Correct |
548 ms |
60940 KB |
Output is correct |
39 |
Correct |
546 ms |
62096 KB |
Output is correct |
40 |
Correct |
547 ms |
62016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
41304 KB |
Output is correct |
2 |
Correct |
20 ms |
41372 KB |
Output is correct |
3 |
Correct |
19 ms |
41388 KB |
Output is correct |
4 |
Correct |
19 ms |
41372 KB |
Output is correct |
5 |
Correct |
20 ms |
41288 KB |
Output is correct |
6 |
Correct |
21 ms |
41404 KB |
Output is correct |
7 |
Correct |
20 ms |
41372 KB |
Output is correct |
8 |
Correct |
19 ms |
41304 KB |
Output is correct |
9 |
Correct |
20 ms |
41388 KB |
Output is correct |
10 |
Correct |
19 ms |
41368 KB |
Output is correct |
11 |
Correct |
63 ms |
51328 KB |
Output is correct |
12 |
Correct |
66 ms |
51304 KB |
Output is correct |
13 |
Correct |
126 ms |
51252 KB |
Output is correct |
14 |
Correct |
133 ms |
51224 KB |
Output is correct |
15 |
Correct |
113 ms |
51312 KB |
Output is correct |
16 |
Correct |
135 ms |
51224 KB |
Output is correct |
17 |
Correct |
125 ms |
51308 KB |
Output is correct |
18 |
Correct |
46 ms |
51492 KB |
Output is correct |
19 |
Correct |
54 ms |
51188 KB |
Output is correct |
20 |
Correct |
98 ms |
51300 KB |
Output is correct |
21 |
Correct |
125 ms |
51304 KB |
Output is correct |
22 |
Correct |
123 ms |
51232 KB |
Output is correct |
23 |
Correct |
90 ms |
51132 KB |
Output is correct |
24 |
Correct |
122 ms |
51224 KB |
Output is correct |
25 |
Correct |
123 ms |
51248 KB |
Output is correct |
26 |
Correct |
45 ms |
51176 KB |
Output is correct |
27 |
Correct |
67 ms |
51312 KB |
Output is correct |
28 |
Correct |
56 ms |
51180 KB |
Output is correct |
29 |
Correct |
113 ms |
51148 KB |
Output is correct |
30 |
Correct |
116 ms |
51240 KB |
Output is correct |
31 |
Correct |
88 ms |
51252 KB |
Output is correct |
32 |
Correct |
139 ms |
51316 KB |
Output is correct |
33 |
Correct |
130 ms |
51304 KB |
Output is correct |
34 |
Correct |
70 ms |
51180 KB |
Output is correct |
35 |
Correct |
118 ms |
51224 KB |
Output is correct |
36 |
Correct |
118 ms |
51260 KB |
Output is correct |
37 |
Correct |
117 ms |
51304 KB |
Output is correct |
38 |
Correct |
120 ms |
51180 KB |
Output is correct |
39 |
Correct |
119 ms |
51232 KB |
Output is correct |
40 |
Correct |
113 ms |
51248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
41304 KB |
Output is correct |
2 |
Correct |
20 ms |
41372 KB |
Output is correct |
3 |
Correct |
19 ms |
41388 KB |
Output is correct |
4 |
Correct |
19 ms |
41372 KB |
Output is correct |
5 |
Correct |
20 ms |
41288 KB |
Output is correct |
6 |
Correct |
21 ms |
41404 KB |
Output is correct |
7 |
Correct |
20 ms |
41372 KB |
Output is correct |
8 |
Correct |
19 ms |
41304 KB |
Output is correct |
9 |
Correct |
20 ms |
41388 KB |
Output is correct |
10 |
Correct |
19 ms |
41368 KB |
Output is correct |
11 |
Correct |
508 ms |
60056 KB |
Output is correct |
12 |
Correct |
519 ms |
59760 KB |
Output is correct |
13 |
Correct |
511 ms |
58920 KB |
Output is correct |
14 |
Correct |
506 ms |
59036 KB |
Output is correct |
15 |
Correct |
505 ms |
59932 KB |
Output is correct |
16 |
Correct |
505 ms |
59152 KB |
Output is correct |
17 |
Correct |
523 ms |
59140 KB |
Output is correct |
18 |
Correct |
371 ms |
60952 KB |
Output is correct |
19 |
Correct |
511 ms |
58128 KB |
Output is correct |
20 |
Correct |
556 ms |
59704 KB |
Output is correct |
21 |
Correct |
529 ms |
63008 KB |
Output is correct |
22 |
Correct |
528 ms |
63176 KB |
Output is correct |
23 |
Correct |
537 ms |
62152 KB |
Output is correct |
24 |
Correct |
510 ms |
62028 KB |
Output is correct |
25 |
Correct |
523 ms |
64032 KB |
Output is correct |
26 |
Correct |
518 ms |
62596 KB |
Output is correct |
27 |
Correct |
532 ms |
62400 KB |
Output is correct |
28 |
Correct |
372 ms |
64964 KB |
Output is correct |
29 |
Correct |
502 ms |
61128 KB |
Output is correct |
30 |
Correct |
512 ms |
63172 KB |
Output is correct |
31 |
Correct |
504 ms |
62928 KB |
Output is correct |
32 |
Correct |
509 ms |
63152 KB |
Output is correct |
33 |
Correct |
514 ms |
61896 KB |
Output is correct |
34 |
Correct |
533 ms |
62020 KB |
Output is correct |
35 |
Correct |
538 ms |
62476 KB |
Output is correct |
36 |
Correct |
404 ms |
61040 KB |
Output is correct |
37 |
Correct |
551 ms |
62932 KB |
Output is correct |
38 |
Correct |
548 ms |
60940 KB |
Output is correct |
39 |
Correct |
546 ms |
62096 KB |
Output is correct |
40 |
Correct |
547 ms |
62016 KB |
Output is correct |
41 |
Correct |
63 ms |
51328 KB |
Output is correct |
42 |
Correct |
66 ms |
51304 KB |
Output is correct |
43 |
Correct |
126 ms |
51252 KB |
Output is correct |
44 |
Correct |
133 ms |
51224 KB |
Output is correct |
45 |
Correct |
113 ms |
51312 KB |
Output is correct |
46 |
Correct |
135 ms |
51224 KB |
Output is correct |
47 |
Correct |
125 ms |
51308 KB |
Output is correct |
48 |
Correct |
46 ms |
51492 KB |
Output is correct |
49 |
Correct |
54 ms |
51188 KB |
Output is correct |
50 |
Correct |
98 ms |
51300 KB |
Output is correct |
51 |
Correct |
125 ms |
51304 KB |
Output is correct |
52 |
Correct |
123 ms |
51232 KB |
Output is correct |
53 |
Correct |
90 ms |
51132 KB |
Output is correct |
54 |
Correct |
122 ms |
51224 KB |
Output is correct |
55 |
Correct |
123 ms |
51248 KB |
Output is correct |
56 |
Correct |
45 ms |
51176 KB |
Output is correct |
57 |
Correct |
67 ms |
51312 KB |
Output is correct |
58 |
Correct |
56 ms |
51180 KB |
Output is correct |
59 |
Correct |
113 ms |
51148 KB |
Output is correct |
60 |
Correct |
116 ms |
51240 KB |
Output is correct |
61 |
Correct |
88 ms |
51252 KB |
Output is correct |
62 |
Correct |
139 ms |
51316 KB |
Output is correct |
63 |
Correct |
130 ms |
51304 KB |
Output is correct |
64 |
Correct |
70 ms |
51180 KB |
Output is correct |
65 |
Correct |
118 ms |
51224 KB |
Output is correct |
66 |
Correct |
118 ms |
51260 KB |
Output is correct |
67 |
Correct |
117 ms |
51304 KB |
Output is correct |
68 |
Correct |
120 ms |
51180 KB |
Output is correct |
69 |
Correct |
119 ms |
51232 KB |
Output is correct |
70 |
Correct |
113 ms |
51248 KB |
Output is correct |
71 |
Runtime error |
101 ms |
65540 KB |
Execution killed with signal 9 |
72 |
Halted |
0 ms |
0 KB |
- |