#include <bits/stdc++.h>
using namespace std;
using namespace std::placeholders;
#define llong long long
#define xx first
#define yy second
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#define all(x) x.begin(), x.end()
// #define rand __rand
// mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); // or mt19937_64
// template<class T = int> T rand(T range = numeric_limits<T>::max()) {
// return (T)(rng() % range);
// }
struct query_string {
llong data;
query_string() {}
query_string& operator= (const string& s) {
data = 0;
for (auto i = s.rbegin(); i != s.rend(); ++i)
data = data << 2 | (*i == '?' ? 3 : (*i - '0'));
return *this;
}
int operator[](size_t pos) {
return (data >> pos >> pos) & 3;
}
};
#define maxl 20
#define maxn (1 << maxl)
#define maxq 1000101
int l, n, q;
int toxic[maxn];
pair<query_string, int*> queries[maxq];
int ans[maxq];
template<class ToxicIter, class QueryIter>
void solve(int level, ToxicIter beg_tox, ToxicIter end_tox, QueryIter beg_que, QueryIter end_que) {
if (beg_que == end_que) return ;
if (level == l) {
assert(distance(beg_tox, end_tox) == 1);
for (auto i = beg_que; i != end_que; ++i)
*(i->yy) = *beg_tox;
return ;
}
auto oneIter = beg_que, questionIter = end_que;
for (auto i = beg_que; i != questionIter; ) {
if (i->xx[level] == 3) swap(*i, *--questionIter);
else if (i->xx[level] == 0) swap(*(i++), *(oneIter++));
else ++i;
}
ToxicIter mid_tox = beg_tox;
advance(mid_tox, distance(beg_tox, end_tox) / 2);
solve(level + 1, beg_tox, mid_tox, beg_que, oneIter);
solve(level + 1, mid_tox, end_tox, oneIter, questionIter);
for (auto i = beg_tox, f = mid_tox; f != end_tox; ++i, ++f)
*i += *f;
solve(level + 1, beg_tox, mid_tox, questionIter, end_que);
for (auto i = beg_tox, f = mid_tox; f != end_tox; ++i, ++f)
*i -= *f;
}
int main(void) {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> l >> q;
n = 1 << l;
{
string s; cin >> s;
rep(i, n) toxic[i] = s[i] - '0';
}
rep(i, q) {
string que; cin >> que;
queries[i].xx = que;
queries[i].yy = ans + i;
}
solve(0, toxic, toxic + n, queries, queries + q);
rep(i, q) cout << ans[i] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
15992 KB |
Output is correct |
2 |
Correct |
15 ms |
15992 KB |
Output is correct |
3 |
Correct |
15 ms |
15992 KB |
Output is correct |
4 |
Correct |
15 ms |
15992 KB |
Output is correct |
5 |
Correct |
15 ms |
15992 KB |
Output is correct |
6 |
Correct |
15 ms |
15996 KB |
Output is correct |
7 |
Correct |
15 ms |
15992 KB |
Output is correct |
8 |
Correct |
15 ms |
16120 KB |
Output is correct |
9 |
Correct |
15 ms |
15992 KB |
Output is correct |
10 |
Correct |
15 ms |
15992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
15992 KB |
Output is correct |
2 |
Correct |
15 ms |
15992 KB |
Output is correct |
3 |
Correct |
15 ms |
15992 KB |
Output is correct |
4 |
Correct |
15 ms |
15992 KB |
Output is correct |
5 |
Correct |
15 ms |
15992 KB |
Output is correct |
6 |
Correct |
15 ms |
15996 KB |
Output is correct |
7 |
Correct |
15 ms |
15992 KB |
Output is correct |
8 |
Correct |
15 ms |
16120 KB |
Output is correct |
9 |
Correct |
15 ms |
15992 KB |
Output is correct |
10 |
Correct |
15 ms |
15992 KB |
Output is correct |
11 |
Correct |
318 ms |
24668 KB |
Output is correct |
12 |
Correct |
348 ms |
24284 KB |
Output is correct |
13 |
Correct |
316 ms |
23544 KB |
Output is correct |
14 |
Correct |
316 ms |
23544 KB |
Output is correct |
15 |
Correct |
325 ms |
24568 KB |
Output is correct |
16 |
Correct |
346 ms |
23720 KB |
Output is correct |
17 |
Correct |
350 ms |
23672 KB |
Output is correct |
18 |
Correct |
229 ms |
25720 KB |
Output is correct |
19 |
Correct |
271 ms |
22588 KB |
Output is correct |
20 |
Correct |
346 ms |
24056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
15992 KB |
Output is correct |
2 |
Correct |
15 ms |
15992 KB |
Output is correct |
3 |
Correct |
15 ms |
15992 KB |
Output is correct |
4 |
Correct |
15 ms |
15992 KB |
Output is correct |
5 |
Correct |
15 ms |
15992 KB |
Output is correct |
6 |
Correct |
15 ms |
15996 KB |
Output is correct |
7 |
Correct |
15 ms |
15992 KB |
Output is correct |
8 |
Correct |
15 ms |
16120 KB |
Output is correct |
9 |
Correct |
15 ms |
15992 KB |
Output is correct |
10 |
Correct |
15 ms |
15992 KB |
Output is correct |
11 |
Correct |
318 ms |
24668 KB |
Output is correct |
12 |
Correct |
348 ms |
24284 KB |
Output is correct |
13 |
Correct |
316 ms |
23544 KB |
Output is correct |
14 |
Correct |
316 ms |
23544 KB |
Output is correct |
15 |
Correct |
325 ms |
24568 KB |
Output is correct |
16 |
Correct |
346 ms |
23720 KB |
Output is correct |
17 |
Correct |
350 ms |
23672 KB |
Output is correct |
18 |
Correct |
229 ms |
25720 KB |
Output is correct |
19 |
Correct |
271 ms |
22588 KB |
Output is correct |
20 |
Correct |
346 ms |
24056 KB |
Output is correct |
21 |
Correct |
363 ms |
24672 KB |
Output is correct |
22 |
Correct |
399 ms |
24824 KB |
Output is correct |
23 |
Correct |
398 ms |
23868 KB |
Output is correct |
24 |
Correct |
374 ms |
23672 KB |
Output is correct |
25 |
Correct |
398 ms |
25700 KB |
Output is correct |
26 |
Correct |
420 ms |
24056 KB |
Output is correct |
27 |
Correct |
465 ms |
23928 KB |
Output is correct |
28 |
Correct |
254 ms |
26744 KB |
Output is correct |
29 |
Correct |
312 ms |
22652 KB |
Output is correct |
30 |
Correct |
392 ms |
24764 KB |
Output is correct |
31 |
Correct |
425 ms |
24824 KB |
Output is correct |
32 |
Correct |
399 ms |
24608 KB |
Output is correct |
33 |
Correct |
345 ms |
23472 KB |
Output is correct |
34 |
Correct |
410 ms |
23644 KB |
Output is correct |
35 |
Correct |
457 ms |
24184 KB |
Output is correct |
36 |
Correct |
233 ms |
22748 KB |
Output is correct |
37 |
Correct |
375 ms |
24668 KB |
Output is correct |
38 |
Correct |
310 ms |
22776 KB |
Output is correct |
39 |
Correct |
401 ms |
23928 KB |
Output is correct |
40 |
Correct |
375 ms |
23600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
15992 KB |
Output is correct |
2 |
Correct |
15 ms |
15992 KB |
Output is correct |
3 |
Correct |
15 ms |
15992 KB |
Output is correct |
4 |
Correct |
15 ms |
15992 KB |
Output is correct |
5 |
Correct |
15 ms |
15992 KB |
Output is correct |
6 |
Correct |
15 ms |
15996 KB |
Output is correct |
7 |
Correct |
15 ms |
15992 KB |
Output is correct |
8 |
Correct |
15 ms |
16120 KB |
Output is correct |
9 |
Correct |
15 ms |
15992 KB |
Output is correct |
10 |
Correct |
15 ms |
15992 KB |
Output is correct |
11 |
Correct |
66 ms |
21712 KB |
Output is correct |
12 |
Correct |
67 ms |
21656 KB |
Output is correct |
13 |
Correct |
186 ms |
21676 KB |
Output is correct |
14 |
Correct |
204 ms |
21656 KB |
Output is correct |
15 |
Correct |
140 ms |
21688 KB |
Output is correct |
16 |
Correct |
209 ms |
21656 KB |
Output is correct |
17 |
Correct |
213 ms |
21656 KB |
Output is correct |
18 |
Correct |
39 ms |
21656 KB |
Output is correct |
19 |
Correct |
63 ms |
21656 KB |
Output is correct |
20 |
Correct |
68 ms |
21660 KB |
Output is correct |
21 |
Correct |
218 ms |
21656 KB |
Output is correct |
22 |
Correct |
207 ms |
21576 KB |
Output is correct |
23 |
Correct |
146 ms |
21656 KB |
Output is correct |
24 |
Correct |
208 ms |
21784 KB |
Output is correct |
25 |
Correct |
213 ms |
21656 KB |
Output is correct |
26 |
Correct |
38 ms |
21656 KB |
Output is correct |
27 |
Correct |
66 ms |
21656 KB |
Output is correct |
28 |
Correct |
61 ms |
21656 KB |
Output is correct |
29 |
Correct |
186 ms |
21656 KB |
Output is correct |
30 |
Correct |
205 ms |
21656 KB |
Output is correct |
31 |
Correct |
135 ms |
21600 KB |
Output is correct |
32 |
Correct |
211 ms |
21656 KB |
Output is correct |
33 |
Correct |
212 ms |
21656 KB |
Output is correct |
34 |
Correct |
39 ms |
21656 KB |
Output is correct |
35 |
Correct |
191 ms |
21656 KB |
Output is correct |
36 |
Correct |
191 ms |
21656 KB |
Output is correct |
37 |
Correct |
192 ms |
21656 KB |
Output is correct |
38 |
Correct |
195 ms |
21652 KB |
Output is correct |
39 |
Correct |
191 ms |
21616 KB |
Output is correct |
40 |
Correct |
192 ms |
21656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
15992 KB |
Output is correct |
2 |
Correct |
15 ms |
15992 KB |
Output is correct |
3 |
Correct |
15 ms |
15992 KB |
Output is correct |
4 |
Correct |
15 ms |
15992 KB |
Output is correct |
5 |
Correct |
15 ms |
15992 KB |
Output is correct |
6 |
Correct |
15 ms |
15996 KB |
Output is correct |
7 |
Correct |
15 ms |
15992 KB |
Output is correct |
8 |
Correct |
15 ms |
16120 KB |
Output is correct |
9 |
Correct |
15 ms |
15992 KB |
Output is correct |
10 |
Correct |
15 ms |
15992 KB |
Output is correct |
11 |
Correct |
318 ms |
24668 KB |
Output is correct |
12 |
Correct |
348 ms |
24284 KB |
Output is correct |
13 |
Correct |
316 ms |
23544 KB |
Output is correct |
14 |
Correct |
316 ms |
23544 KB |
Output is correct |
15 |
Correct |
325 ms |
24568 KB |
Output is correct |
16 |
Correct |
346 ms |
23720 KB |
Output is correct |
17 |
Correct |
350 ms |
23672 KB |
Output is correct |
18 |
Correct |
229 ms |
25720 KB |
Output is correct |
19 |
Correct |
271 ms |
22588 KB |
Output is correct |
20 |
Correct |
346 ms |
24056 KB |
Output is correct |
21 |
Correct |
363 ms |
24672 KB |
Output is correct |
22 |
Correct |
399 ms |
24824 KB |
Output is correct |
23 |
Correct |
398 ms |
23868 KB |
Output is correct |
24 |
Correct |
374 ms |
23672 KB |
Output is correct |
25 |
Correct |
398 ms |
25700 KB |
Output is correct |
26 |
Correct |
420 ms |
24056 KB |
Output is correct |
27 |
Correct |
465 ms |
23928 KB |
Output is correct |
28 |
Correct |
254 ms |
26744 KB |
Output is correct |
29 |
Correct |
312 ms |
22652 KB |
Output is correct |
30 |
Correct |
392 ms |
24764 KB |
Output is correct |
31 |
Correct |
425 ms |
24824 KB |
Output is correct |
32 |
Correct |
399 ms |
24608 KB |
Output is correct |
33 |
Correct |
345 ms |
23472 KB |
Output is correct |
34 |
Correct |
410 ms |
23644 KB |
Output is correct |
35 |
Correct |
457 ms |
24184 KB |
Output is correct |
36 |
Correct |
233 ms |
22748 KB |
Output is correct |
37 |
Correct |
375 ms |
24668 KB |
Output is correct |
38 |
Correct |
310 ms |
22776 KB |
Output is correct |
39 |
Correct |
401 ms |
23928 KB |
Output is correct |
40 |
Correct |
375 ms |
23600 KB |
Output is correct |
41 |
Correct |
66 ms |
21712 KB |
Output is correct |
42 |
Correct |
67 ms |
21656 KB |
Output is correct |
43 |
Correct |
186 ms |
21676 KB |
Output is correct |
44 |
Correct |
204 ms |
21656 KB |
Output is correct |
45 |
Correct |
140 ms |
21688 KB |
Output is correct |
46 |
Correct |
209 ms |
21656 KB |
Output is correct |
47 |
Correct |
213 ms |
21656 KB |
Output is correct |
48 |
Correct |
39 ms |
21656 KB |
Output is correct |
49 |
Correct |
63 ms |
21656 KB |
Output is correct |
50 |
Correct |
68 ms |
21660 KB |
Output is correct |
51 |
Correct |
218 ms |
21656 KB |
Output is correct |
52 |
Correct |
207 ms |
21576 KB |
Output is correct |
53 |
Correct |
146 ms |
21656 KB |
Output is correct |
54 |
Correct |
208 ms |
21784 KB |
Output is correct |
55 |
Correct |
213 ms |
21656 KB |
Output is correct |
56 |
Correct |
38 ms |
21656 KB |
Output is correct |
57 |
Correct |
66 ms |
21656 KB |
Output is correct |
58 |
Correct |
61 ms |
21656 KB |
Output is correct |
59 |
Correct |
186 ms |
21656 KB |
Output is correct |
60 |
Correct |
205 ms |
21656 KB |
Output is correct |
61 |
Correct |
135 ms |
21600 KB |
Output is correct |
62 |
Correct |
211 ms |
21656 KB |
Output is correct |
63 |
Correct |
212 ms |
21656 KB |
Output is correct |
64 |
Correct |
39 ms |
21656 KB |
Output is correct |
65 |
Correct |
191 ms |
21656 KB |
Output is correct |
66 |
Correct |
191 ms |
21656 KB |
Output is correct |
67 |
Correct |
192 ms |
21656 KB |
Output is correct |
68 |
Correct |
195 ms |
21652 KB |
Output is correct |
69 |
Correct |
191 ms |
21616 KB |
Output is correct |
70 |
Correct |
192 ms |
21656 KB |
Output is correct |
71 |
Correct |
569 ms |
50672 KB |
Output is correct |
72 |
Correct |
626 ms |
50952 KB |
Output is correct |
73 |
Correct |
1089 ms |
49432 KB |
Output is correct |
74 |
Correct |
1219 ms |
49776 KB |
Output is correct |
75 |
Correct |
884 ms |
51636 KB |
Output is correct |
76 |
Correct |
1261 ms |
49928 KB |
Output is correct |
77 |
Correct |
1319 ms |
50056 KB |
Output is correct |
78 |
Correct |
350 ms |
53672 KB |
Output is correct |
79 |
Correct |
472 ms |
47652 KB |
Output is correct |
80 |
Correct |
650 ms |
50944 KB |
Output is correct |
81 |
Correct |
1215 ms |
50816 KB |
Output is correct |
82 |
Correct |
1223 ms |
49712 KB |
Output is correct |
83 |
Correct |
904 ms |
48860 KB |
Output is correct |
84 |
Correct |
1245 ms |
49612 KB |
Output is correct |
85 |
Correct |
1322 ms |
49924 KB |
Output is correct |
86 |
Correct |
329 ms |
47688 KB |
Output is correct |
87 |
Correct |
581 ms |
50728 KB |
Output is correct |
88 |
Correct |
521 ms |
47812 KB |
Output is correct |
89 |
Correct |
1115 ms |
49492 KB |
Output is correct |
90 |
Correct |
1216 ms |
49672 KB |
Output is correct |
91 |
Correct |
885 ms |
48776 KB |
Output is correct |
92 |
Correct |
1279 ms |
50156 KB |
Output is correct |
93 |
Correct |
1295 ms |
49884 KB |
Output is correct |
94 |
Correct |
350 ms |
47728 KB |
Output is correct |
95 |
Correct |
1139 ms |
49876 KB |
Output is correct |
96 |
Correct |
1181 ms |
49472 KB |
Output is correct |
97 |
Correct |
1140 ms |
49880 KB |
Output is correct |
98 |
Correct |
1134 ms |
49620 KB |
Output is correct |
99 |
Correct |
1136 ms |
49764 KB |
Output is correct |
100 |
Correct |
1148 ms |
50028 KB |
Output is correct |