// Src : Vux2Code
// Note : none
#include <bits/stdc++.h>
#define pq_rvs pll,vector<pll>,greater<pll>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pll;
struct Edge {ll u, v, w;};
const ll alp = 4;
const vector <ll> emptyVec = {};
int enc (char x) {
if (x == 'A') return 0;
if (x == 'C') return 1;
if (x == 'G') return 2;
if (x == 'U') return 3;
return -1;
}
struct PreTrie {
struct Node {
Node* next [alp];
ll l, r;
Node () {
for (int i = 0; i < alp; i ++) next [i] = NULL;
l = -1; r = -1;
}
};
Node* root;
PreTrie () {
root = new Node ();
}
void add (string x, ll y) {
Node* pos = root;
for (int i = 0; i < x. size (); i ++) {
if (pos -> next [enc (x [i])] == NULL) pos -> next [enc (x [i])] = new Node ();
pos = pos -> next [enc (x [i])];
if (pos -> l == -1) pos -> l = y;
pos -> r = max (pos -> r, y);
}
}
pll fin (string x) {
Node* pos = root;
for (int i = 0; i < x. size (); i ++) {
if (pos -> next [enc (x [i])] == NULL) return {-1, -1};
pos = pos -> next [enc (x [i])];
}
return {pos -> l, pos -> r};
}
};
struct SufTrie {
struct Node {
Node* next [alp];
vector <ll> vec;
Node () {
for (int i = 0; i < alp; i ++) next [i] = NULL;
vec. clear ();
}
};
Node* root;
SufTrie () {
root = new Node ();
}
void add (string x, ll y) {
Node* pos = root;
for (int i = x. size () - 1; i >= 0; i --) {
if (pos -> next [enc (x [i])] == NULL) pos -> next [enc (x [i])] = new Node ();
pos = pos -> next [enc (x [i])];
pos -> vec. push_back (y);
}
}
vector <ll> fin (string x) {
Node* pos = root;
for (int i = x. size () - 1; i >= 0; i --) {
if (pos -> next [enc (x [i])] == NULL) return emptyVec;
pos = pos -> next [enc (x [i])];
}
return pos ->vec;
}
};
const ll maxN = 2e5 + 5, inf64 = 1e18, mod = 1e9 + 7, maxLog = 20;
ll t = 1;
ll n, m;
string s [maxN], p, q;
PreTrie pre;
SufTrie suf;
vector <ll> tmp;
pll tmpLR;
void solve () {
cin >> n >> m;
for (int i = 1; i <= n; i ++) cin >> s [i];
sort (s + 1, s + n + 1);
for (int i = 1; i <= n; i ++) {
pre. add (s [i], i);
suf. add (s [i], i);
}
for (int i = 1; i <= m; i ++) {
cin >> p >> q;
tmpLR = pre. fin (p);
tmp = suf. fin (q);
cout << upper_bound (tmp. begin (), tmp. end (), tmpLR. second) - lower_bound (tmp. begin (), tmp. end (), tmpLR. first) << '\n';
}
}
int main (){
ios::sync_with_stdio (0);
cin. tie (0);
cout. tie (0);
// #define task "chill"
// freopen (task".inp", "r", stdin);
// freopen (task".out", "w", stdout);
//cin >> t;
while (t --) solve ();
return 0;
}
Compilation message
selling_rna.cpp: In member function 'void PreTrie::add(std::string, ll)':
selling_rna.cpp:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for (int i = 0; i < x. size (); i ++) {
| ~~^~~~~~~~~~~~
selling_rna.cpp: In member function 'pll PreTrie::fin(std::string)':
selling_rna.cpp:48:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = 0; i < x. size (); i ++) {
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6716 KB |
Output is correct |
2 |
Correct |
3 ms |
6908 KB |
Output is correct |
3 |
Correct |
2 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6744 KB |
Output is correct |
6 |
Correct |
3 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
210 ms |
197720 KB |
Output is correct |
2 |
Correct |
238 ms |
188140 KB |
Output is correct |
3 |
Correct |
167 ms |
154916 KB |
Output is correct |
4 |
Correct |
149 ms |
148220 KB |
Output is correct |
5 |
Correct |
201 ms |
201140 KB |
Output is correct |
6 |
Correct |
224 ms |
203856 KB |
Output is correct |
7 |
Correct |
67 ms |
29644 KB |
Output is correct |
8 |
Correct |
162 ms |
138588 KB |
Output is correct |
9 |
Correct |
156 ms |
120656 KB |
Output is correct |
10 |
Correct |
113 ms |
115536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
652 ms |
8896 KB |
Output is correct |
2 |
Correct |
54 ms |
8816 KB |
Output is correct |
3 |
Correct |
236 ms |
8812 KB |
Output is correct |
4 |
Correct |
84 ms |
8148 KB |
Output is correct |
5 |
Correct |
217 ms |
8800 KB |
Output is correct |
6 |
Correct |
384 ms |
8820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6716 KB |
Output is correct |
2 |
Correct |
3 ms |
6908 KB |
Output is correct |
3 |
Correct |
2 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6744 KB |
Output is correct |
6 |
Correct |
3 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
210 ms |
197720 KB |
Output is correct |
9 |
Correct |
238 ms |
188140 KB |
Output is correct |
10 |
Correct |
167 ms |
154916 KB |
Output is correct |
11 |
Correct |
149 ms |
148220 KB |
Output is correct |
12 |
Correct |
201 ms |
201140 KB |
Output is correct |
13 |
Correct |
224 ms |
203856 KB |
Output is correct |
14 |
Correct |
67 ms |
29644 KB |
Output is correct |
15 |
Correct |
162 ms |
138588 KB |
Output is correct |
16 |
Correct |
156 ms |
120656 KB |
Output is correct |
17 |
Correct |
113 ms |
115536 KB |
Output is correct |
18 |
Correct |
652 ms |
8896 KB |
Output is correct |
19 |
Correct |
54 ms |
8816 KB |
Output is correct |
20 |
Correct |
236 ms |
8812 KB |
Output is correct |
21 |
Correct |
84 ms |
8148 KB |
Output is correct |
22 |
Correct |
217 ms |
8800 KB |
Output is correct |
23 |
Correct |
384 ms |
8820 KB |
Output is correct |
24 |
Correct |
190 ms |
165460 KB |
Output is correct |
25 |
Correct |
266 ms |
165712 KB |
Output is correct |
26 |
Correct |
193 ms |
163664 KB |
Output is correct |
27 |
Correct |
174 ms |
130712 KB |
Output is correct |
28 |
Correct |
1316 ms |
52552 KB |
Output is correct |
29 |
Correct |
147 ms |
19772 KB |
Output is correct |