#include <array>
#include <typeinfo>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define trav(x, v) for (auto &x : v)
#define sz(x) int((x).size())
#define lb(x...) lower_bound(x)
#define ub(x...) upper_bound(x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define eb(x...) emplace_back(x)
constexpr int A = 4;
map<char, int> cmp = {{'A', 0}, {'C', 1}, {'G', 2}, {'U', 3}};
struct T {
array<T*, A> nxt;
vector<int> idx;
T() { fill(all(nxt), nullptr); }
template<class it>
void insert(it st, it en, int i) {
idx.eb(i);
if (st == en) return;
auto &x = nxt[cmp[*st]];
if (!x) x = new T();
x->insert(next(st), en, i);
}
template<class it>
int query(it st, it en, int l, int r) { // [l, r)
if (st == en)
return lb(all(idx), r) - lb(all(idx), l);
auto &x = nxt[cmp[*st]];
return x ? x->query(next(st), en, l, r) : 0;
}
} t;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<string> s(n);
rep(i, 0, n) cin >> s[i];
sort(all(s));
rep(i, 0, n) t.insert(rall(s[i]), i);
while (m--) {
string p, q; cin >> p >> q;
int l = lb(all(s), p) - begin(s);
++p.back();
int r = ub(all(s), p) - begin(s);
cout << t.query(rall(q), l, r) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
254 ms |
191156 KB |
Output is correct |
2 |
Correct |
250 ms |
181240 KB |
Output is correct |
3 |
Correct |
81 ms |
18300 KB |
Output is correct |
4 |
Correct |
84 ms |
18012 KB |
Output is correct |
5 |
Correct |
182 ms |
118776 KB |
Output is correct |
6 |
Correct |
179 ms |
120440 KB |
Output is correct |
7 |
Correct |
78 ms |
15992 KB |
Output is correct |
8 |
Correct |
186 ms |
81332 KB |
Output is correct |
9 |
Correct |
145 ms |
70520 KB |
Output is correct |
10 |
Correct |
122 ms |
65912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
3572 KB |
Output is correct |
2 |
Correct |
40 ms |
2808 KB |
Output is correct |
3 |
Correct |
42 ms |
3060 KB |
Output is correct |
4 |
Correct |
31 ms |
2676 KB |
Output is correct |
5 |
Correct |
36 ms |
2560 KB |
Output is correct |
6 |
Correct |
45 ms |
2932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
254 ms |
191156 KB |
Output is correct |
9 |
Correct |
250 ms |
181240 KB |
Output is correct |
10 |
Correct |
81 ms |
18300 KB |
Output is correct |
11 |
Correct |
84 ms |
18012 KB |
Output is correct |
12 |
Correct |
182 ms |
118776 KB |
Output is correct |
13 |
Correct |
179 ms |
120440 KB |
Output is correct |
14 |
Correct |
78 ms |
15992 KB |
Output is correct |
15 |
Correct |
186 ms |
81332 KB |
Output is correct |
16 |
Correct |
145 ms |
70520 KB |
Output is correct |
17 |
Correct |
122 ms |
65912 KB |
Output is correct |
18 |
Correct |
42 ms |
3572 KB |
Output is correct |
19 |
Correct |
40 ms |
2808 KB |
Output is correct |
20 |
Correct |
42 ms |
3060 KB |
Output is correct |
21 |
Correct |
31 ms |
2676 KB |
Output is correct |
22 |
Correct |
36 ms |
2560 KB |
Output is correct |
23 |
Correct |
45 ms |
2932 KB |
Output is correct |
24 |
Correct |
264 ms |
157560 KB |
Output is correct |
25 |
Correct |
280 ms |
157688 KB |
Output is correct |
26 |
Correct |
241 ms |
155640 KB |
Output is correct |
27 |
Correct |
90 ms |
17784 KB |
Output is correct |
28 |
Correct |
232 ms |
38900 KB |
Output is correct |
29 |
Correct |
122 ms |
12396 KB |
Output is correct |