#include <bits/stdc++.h>
using namespace std;
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
const int N = (int)2e6+10;
vector<int> V[N];
int T[2][4][N];
int L[N], R[N];
int n, m, I[2];
string s[N];
void add(string &s, int j, int t, bool r=0){
int v = 1;
for(int i = 0; i < sz(s); i++){
char u = s[r?sz(s)-1-i:i];
int c = (u=='A'?0:u=='C'?1:u=='G'?2:3);
if(!T[t][c][v]) T[t][c][v]=I[t]++;
v = T[t][c][v];
if(!t){
if(!L[v]) L[v]=j;
R[v]=max(R[v],j);
}
else V[v].push_back(j);
}
}
int get(string &s, int t, bool r=0){
int v = 1;
for(int i = 0; i < sz(s); i++){
char u = s[r?sz(s)-1-i:i];
int c = (u=='A'?0:u=='C'?1:u=='G'?2:3);
v = T[t][c][v]; if(!v) return 0;
}
return v;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> m; I[0]=I[1]=2;
for(int i = 0; i < n; i++)
cin >> s[i]; sort(s,s+n);
for(int i = 0; i < n; i++)
add(s[i],i+1,0),add(s[i],i+1,1,1);
for(int i = 0; i < m; i++){
string s, t; cin >> s >> t;
int I = get(s,0), I2=get(t,1,1);
int l = L[I], r=R[I];
int p1 = lower_bound(all(V[I2]),l)-begin(V[I2]);
int p2 = upper_bound(all(V[I2]),r)-begin(V[I2]);
cout << max(0, p2-p1) << "\n";
}
}
Compilation message
selling_rna.cpp: In function 'int main()':
selling_rna.cpp:41:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
41 | for(int i = 0; i < n; i++)
| ^~~
selling_rna.cpp:42:16: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
42 | cin >> s[i]; sort(s,s+n);
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
109896 KB |
Output is correct |
2 |
Correct |
47 ms |
109944 KB |
Output is correct |
3 |
Correct |
44 ms |
109900 KB |
Output is correct |
4 |
Correct |
43 ms |
109908 KB |
Output is correct |
5 |
Correct |
45 ms |
109900 KB |
Output is correct |
6 |
Correct |
52 ms |
109872 KB |
Output is correct |
7 |
Correct |
51 ms |
109900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
163 ms |
204528 KB |
Output is correct |
2 |
Correct |
163 ms |
199532 KB |
Output is correct |
3 |
Correct |
109 ms |
168604 KB |
Output is correct |
4 |
Correct |
101 ms |
166344 KB |
Output is correct |
5 |
Correct |
152 ms |
197012 KB |
Output is correct |
6 |
Correct |
154 ms |
198308 KB |
Output is correct |
7 |
Correct |
80 ms |
119992 KB |
Output is correct |
8 |
Correct |
143 ms |
155520 KB |
Output is correct |
9 |
Correct |
128 ms |
156084 KB |
Output is correct |
10 |
Correct |
117 ms |
154892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
110864 KB |
Output is correct |
2 |
Correct |
58 ms |
110800 KB |
Output is correct |
3 |
Correct |
62 ms |
110796 KB |
Output is correct |
4 |
Correct |
58 ms |
110620 KB |
Output is correct |
5 |
Correct |
58 ms |
110840 KB |
Output is correct |
6 |
Correct |
62 ms |
110780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
109896 KB |
Output is correct |
2 |
Correct |
47 ms |
109944 KB |
Output is correct |
3 |
Correct |
44 ms |
109900 KB |
Output is correct |
4 |
Correct |
43 ms |
109908 KB |
Output is correct |
5 |
Correct |
45 ms |
109900 KB |
Output is correct |
6 |
Correct |
52 ms |
109872 KB |
Output is correct |
7 |
Correct |
51 ms |
109900 KB |
Output is correct |
8 |
Correct |
163 ms |
204528 KB |
Output is correct |
9 |
Correct |
163 ms |
199532 KB |
Output is correct |
10 |
Correct |
109 ms |
168604 KB |
Output is correct |
11 |
Correct |
101 ms |
166344 KB |
Output is correct |
12 |
Correct |
152 ms |
197012 KB |
Output is correct |
13 |
Correct |
154 ms |
198308 KB |
Output is correct |
14 |
Correct |
80 ms |
119992 KB |
Output is correct |
15 |
Correct |
143 ms |
155520 KB |
Output is correct |
16 |
Correct |
128 ms |
156084 KB |
Output is correct |
17 |
Correct |
117 ms |
154892 KB |
Output is correct |
18 |
Correct |
61 ms |
110864 KB |
Output is correct |
19 |
Correct |
58 ms |
110800 KB |
Output is correct |
20 |
Correct |
62 ms |
110796 KB |
Output is correct |
21 |
Correct |
58 ms |
110620 KB |
Output is correct |
22 |
Correct |
58 ms |
110840 KB |
Output is correct |
23 |
Correct |
62 ms |
110780 KB |
Output is correct |
24 |
Correct |
174 ms |
187832 KB |
Output is correct |
25 |
Correct |
171 ms |
187864 KB |
Output is correct |
26 |
Correct |
161 ms |
186856 KB |
Output is correct |
27 |
Correct |
118 ms |
159632 KB |
Output is correct |
28 |
Correct |
158 ms |
131020 KB |
Output is correct |
29 |
Correct |
93 ms |
115192 KB |
Output is correct |