#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define bl " "
#define endl "\n"
#define all(v) v.begin(), v.end()
#define comp(v) v.erase(unique(all(v)), v.end())
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1000100;
const int MOD = 1e9+7;
struct Query {
string s; int x;
}qry[MAXN];
vector<int> v;
int ans[MAXN];
void solve(int s, int e, int l, int r, int x) {
if(s > e) return;
if(l == r) {
for(int i = s; i <= e; i++) ans[qry[i].x] = v[l];
return;
}
int a = s, mid = l+r>>1;
for(a = s; a <= e; a++) {
if(qry[a].s[x] != '0') break;
}
solve(s, a-1, l, mid, x+1);
s = a;
for(; a <= e; a++) {
if(qry[a].s[x] != '1') break;
}
solve(s, a-1, mid+1, r, x+1);
s = a;
for(int i = l, j = mid+1; j <= r; i++, j++) v[i] += v[j];
solve(s, e, l, mid, x+1);
for(int i = l, j = mid+1; j <= r; i++, j++) v[i] -= v[j];
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int l, q; cin >> l >> q;
string s; cin >> s;
for(int i = 0; i < s.size(); i++) v.push_back(s[i]-'0');
for(int i = 0; i < q; i++) {
cin >> qry[i].s; qry[i].x = i;
}
sort(qry, qry+q, [](Query a, Query b){return a.s < b.s;});
solve(0, q-1, 0, (1<<l)-1, 0);
for(int i = 0; i < q; i++) cout << ans[i] << endl;
}
Compilation message
snake_escaping.cpp: In function 'void solve(int, int, int, int, int)':
snake_escaping.cpp:32:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
32 | int a = s, mid = l+r>>1;
| ~^~
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:57:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i = 0; i < s.size(); i++) v.push_back(s[i]-'0');
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
41304 KB |
Output is correct |
2 |
Correct |
9 ms |
41308 KB |
Output is correct |
3 |
Correct |
9 ms |
41308 KB |
Output is correct |
4 |
Correct |
9 ms |
41308 KB |
Output is correct |
5 |
Correct |
8 ms |
41196 KB |
Output is correct |
6 |
Correct |
10 ms |
41304 KB |
Output is correct |
7 |
Correct |
9 ms |
41320 KB |
Output is correct |
8 |
Correct |
9 ms |
41152 KB |
Output is correct |
9 |
Correct |
9 ms |
41816 KB |
Output is correct |
10 |
Correct |
8 ms |
41308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
41304 KB |
Output is correct |
2 |
Correct |
9 ms |
41308 KB |
Output is correct |
3 |
Correct |
9 ms |
41308 KB |
Output is correct |
4 |
Correct |
9 ms |
41308 KB |
Output is correct |
5 |
Correct |
8 ms |
41196 KB |
Output is correct |
6 |
Correct |
10 ms |
41304 KB |
Output is correct |
7 |
Correct |
9 ms |
41320 KB |
Output is correct |
8 |
Correct |
9 ms |
41152 KB |
Output is correct |
9 |
Correct |
9 ms |
41816 KB |
Output is correct |
10 |
Correct |
8 ms |
41308 KB |
Output is correct |
11 |
Correct |
554 ms |
58336 KB |
Output is correct |
12 |
Correct |
594 ms |
58036 KB |
Output is correct |
13 |
Correct |
583 ms |
57136 KB |
Output is correct |
14 |
Correct |
568 ms |
57168 KB |
Output is correct |
15 |
Correct |
575 ms |
58164 KB |
Output is correct |
16 |
Correct |
600 ms |
57276 KB |
Output is correct |
17 |
Correct |
641 ms |
57396 KB |
Output is correct |
18 |
Correct |
502 ms |
59224 KB |
Output is correct |
19 |
Correct |
555 ms |
56152 KB |
Output is correct |
20 |
Correct |
581 ms |
57916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
41304 KB |
Output is correct |
2 |
Correct |
9 ms |
41308 KB |
Output is correct |
3 |
Correct |
9 ms |
41308 KB |
Output is correct |
4 |
Correct |
9 ms |
41308 KB |
Output is correct |
5 |
Correct |
8 ms |
41196 KB |
Output is correct |
6 |
Correct |
10 ms |
41304 KB |
Output is correct |
7 |
Correct |
9 ms |
41320 KB |
Output is correct |
8 |
Correct |
9 ms |
41152 KB |
Output is correct |
9 |
Correct |
9 ms |
41816 KB |
Output is correct |
10 |
Correct |
8 ms |
41308 KB |
Output is correct |
11 |
Correct |
554 ms |
58336 KB |
Output is correct |
12 |
Correct |
594 ms |
58036 KB |
Output is correct |
13 |
Correct |
583 ms |
57136 KB |
Output is correct |
14 |
Correct |
568 ms |
57168 KB |
Output is correct |
15 |
Correct |
575 ms |
58164 KB |
Output is correct |
16 |
Correct |
600 ms |
57276 KB |
Output is correct |
17 |
Correct |
641 ms |
57396 KB |
Output is correct |
18 |
Correct |
502 ms |
59224 KB |
Output is correct |
19 |
Correct |
555 ms |
56152 KB |
Output is correct |
20 |
Correct |
581 ms |
57916 KB |
Output is correct |
21 |
Correct |
592 ms |
61264 KB |
Output is correct |
22 |
Correct |
603 ms |
61280 KB |
Output is correct |
23 |
Correct |
683 ms |
60244 KB |
Output is correct |
24 |
Correct |
665 ms |
60280 KB |
Output is correct |
25 |
Correct |
642 ms |
62068 KB |
Output is correct |
26 |
Correct |
711 ms |
60752 KB |
Output is correct |
27 |
Correct |
713 ms |
60664 KB |
Output is correct |
28 |
Correct |
495 ms |
63096 KB |
Output is correct |
29 |
Correct |
595 ms |
59220 KB |
Output is correct |
30 |
Correct |
608 ms |
61264 KB |
Output is correct |
31 |
Correct |
677 ms |
61264 KB |
Output is correct |
32 |
Correct |
659 ms |
61176 KB |
Output is correct |
33 |
Correct |
621 ms |
60152 KB |
Output is correct |
34 |
Correct |
684 ms |
60156 KB |
Output is correct |
35 |
Correct |
711 ms |
60500 KB |
Output is correct |
36 |
Correct |
519 ms |
59220 KB |
Output is correct |
37 |
Correct |
582 ms |
61180 KB |
Output is correct |
38 |
Correct |
615 ms |
59132 KB |
Output is correct |
39 |
Correct |
684 ms |
60500 KB |
Output is correct |
40 |
Correct |
648 ms |
60244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
41304 KB |
Output is correct |
2 |
Correct |
9 ms |
41308 KB |
Output is correct |
3 |
Correct |
9 ms |
41308 KB |
Output is correct |
4 |
Correct |
9 ms |
41308 KB |
Output is correct |
5 |
Correct |
8 ms |
41196 KB |
Output is correct |
6 |
Correct |
10 ms |
41304 KB |
Output is correct |
7 |
Correct |
9 ms |
41320 KB |
Output is correct |
8 |
Correct |
9 ms |
41152 KB |
Output is correct |
9 |
Correct |
9 ms |
41816 KB |
Output is correct |
10 |
Correct |
8 ms |
41308 KB |
Output is correct |
11 |
Correct |
86 ms |
53224 KB |
Output is correct |
12 |
Correct |
87 ms |
53224 KB |
Output is correct |
13 |
Correct |
171 ms |
53220 KB |
Output is correct |
14 |
Correct |
169 ms |
53224 KB |
Output is correct |
15 |
Correct |
130 ms |
53220 KB |
Output is correct |
16 |
Correct |
172 ms |
53224 KB |
Output is correct |
17 |
Correct |
172 ms |
53140 KB |
Output is correct |
18 |
Correct |
56 ms |
53224 KB |
Output is correct |
19 |
Correct |
87 ms |
52964 KB |
Output is correct |
20 |
Correct |
89 ms |
53220 KB |
Output is correct |
21 |
Correct |
155 ms |
53160 KB |
Output is correct |
22 |
Correct |
167 ms |
53040 KB |
Output is correct |
23 |
Correct |
134 ms |
53400 KB |
Output is correct |
24 |
Correct |
168 ms |
53220 KB |
Output is correct |
25 |
Correct |
172 ms |
53128 KB |
Output is correct |
26 |
Correct |
59 ms |
53156 KB |
Output is correct |
27 |
Correct |
92 ms |
53128 KB |
Output is correct |
28 |
Correct |
87 ms |
52972 KB |
Output is correct |
29 |
Correct |
158 ms |
53128 KB |
Output is correct |
30 |
Correct |
167 ms |
53220 KB |
Output is correct |
31 |
Correct |
131 ms |
53088 KB |
Output is correct |
32 |
Correct |
170 ms |
53224 KB |
Output is correct |
33 |
Correct |
176 ms |
53128 KB |
Output is correct |
34 |
Correct |
58 ms |
52912 KB |
Output is correct |
35 |
Correct |
157 ms |
53088 KB |
Output is correct |
36 |
Correct |
160 ms |
53140 KB |
Output is correct |
37 |
Correct |
158 ms |
53040 KB |
Output is correct |
38 |
Correct |
158 ms |
53208 KB |
Output is correct |
39 |
Correct |
159 ms |
53132 KB |
Output is correct |
40 |
Correct |
158 ms |
53220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
41304 KB |
Output is correct |
2 |
Correct |
9 ms |
41308 KB |
Output is correct |
3 |
Correct |
9 ms |
41308 KB |
Output is correct |
4 |
Correct |
9 ms |
41308 KB |
Output is correct |
5 |
Correct |
8 ms |
41196 KB |
Output is correct |
6 |
Correct |
10 ms |
41304 KB |
Output is correct |
7 |
Correct |
9 ms |
41320 KB |
Output is correct |
8 |
Correct |
9 ms |
41152 KB |
Output is correct |
9 |
Correct |
9 ms |
41816 KB |
Output is correct |
10 |
Correct |
8 ms |
41308 KB |
Output is correct |
11 |
Correct |
554 ms |
58336 KB |
Output is correct |
12 |
Correct |
594 ms |
58036 KB |
Output is correct |
13 |
Correct |
583 ms |
57136 KB |
Output is correct |
14 |
Correct |
568 ms |
57168 KB |
Output is correct |
15 |
Correct |
575 ms |
58164 KB |
Output is correct |
16 |
Correct |
600 ms |
57276 KB |
Output is correct |
17 |
Correct |
641 ms |
57396 KB |
Output is correct |
18 |
Correct |
502 ms |
59224 KB |
Output is correct |
19 |
Correct |
555 ms |
56152 KB |
Output is correct |
20 |
Correct |
581 ms |
57916 KB |
Output is correct |
21 |
Correct |
592 ms |
61264 KB |
Output is correct |
22 |
Correct |
603 ms |
61280 KB |
Output is correct |
23 |
Correct |
683 ms |
60244 KB |
Output is correct |
24 |
Correct |
665 ms |
60280 KB |
Output is correct |
25 |
Correct |
642 ms |
62068 KB |
Output is correct |
26 |
Correct |
711 ms |
60752 KB |
Output is correct |
27 |
Correct |
713 ms |
60664 KB |
Output is correct |
28 |
Correct |
495 ms |
63096 KB |
Output is correct |
29 |
Correct |
595 ms |
59220 KB |
Output is correct |
30 |
Correct |
608 ms |
61264 KB |
Output is correct |
31 |
Correct |
677 ms |
61264 KB |
Output is correct |
32 |
Correct |
659 ms |
61176 KB |
Output is correct |
33 |
Correct |
621 ms |
60152 KB |
Output is correct |
34 |
Correct |
684 ms |
60156 KB |
Output is correct |
35 |
Correct |
711 ms |
60500 KB |
Output is correct |
36 |
Correct |
519 ms |
59220 KB |
Output is correct |
37 |
Correct |
582 ms |
61180 KB |
Output is correct |
38 |
Correct |
615 ms |
59132 KB |
Output is correct |
39 |
Correct |
684 ms |
60500 KB |
Output is correct |
40 |
Correct |
648 ms |
60244 KB |
Output is correct |
41 |
Correct |
86 ms |
53224 KB |
Output is correct |
42 |
Correct |
87 ms |
53224 KB |
Output is correct |
43 |
Correct |
171 ms |
53220 KB |
Output is correct |
44 |
Correct |
169 ms |
53224 KB |
Output is correct |
45 |
Correct |
130 ms |
53220 KB |
Output is correct |
46 |
Correct |
172 ms |
53224 KB |
Output is correct |
47 |
Correct |
172 ms |
53140 KB |
Output is correct |
48 |
Correct |
56 ms |
53224 KB |
Output is correct |
49 |
Correct |
87 ms |
52964 KB |
Output is correct |
50 |
Correct |
89 ms |
53220 KB |
Output is correct |
51 |
Correct |
155 ms |
53160 KB |
Output is correct |
52 |
Correct |
167 ms |
53040 KB |
Output is correct |
53 |
Correct |
134 ms |
53400 KB |
Output is correct |
54 |
Correct |
168 ms |
53220 KB |
Output is correct |
55 |
Correct |
172 ms |
53128 KB |
Output is correct |
56 |
Correct |
59 ms |
53156 KB |
Output is correct |
57 |
Correct |
92 ms |
53128 KB |
Output is correct |
58 |
Correct |
87 ms |
52972 KB |
Output is correct |
59 |
Correct |
158 ms |
53128 KB |
Output is correct |
60 |
Correct |
167 ms |
53220 KB |
Output is correct |
61 |
Correct |
131 ms |
53088 KB |
Output is correct |
62 |
Correct |
170 ms |
53224 KB |
Output is correct |
63 |
Correct |
176 ms |
53128 KB |
Output is correct |
64 |
Correct |
58 ms |
52912 KB |
Output is correct |
65 |
Correct |
157 ms |
53088 KB |
Output is correct |
66 |
Correct |
160 ms |
53140 KB |
Output is correct |
67 |
Correct |
158 ms |
53040 KB |
Output is correct |
68 |
Correct |
158 ms |
53208 KB |
Output is correct |
69 |
Correct |
159 ms |
53132 KB |
Output is correct |
70 |
Correct |
158 ms |
53220 KB |
Output is correct |
71 |
Runtime error |
72 ms |
65536 KB |
Execution killed with signal 9 |
72 |
Halted |
0 ms |
0 KB |
- |