#include<bits/stdc++.h>
#define f first
#define s second
#define ends endss
using namespace std;
const int N=1e5+5,mod=1e9+7;
int t,n,m,pwr[N],ans[N],tree[N],aft[40*N][5],cur,timer,L,R;
vector<pair<int,pair<int,int> > >Q[N],P[N];;
vector<int> ends[40*N][2];
string s[N],s1[N];
int get(char c){
if(c=='A') return 1;
if(c=='G') return 2;
if(c=='U') return 3;
return 0;
}
void add(string s,int ind,int f){
int u = 0;
for(int i=0;i<s.size();i++){
if(!aft[u][get(s[i])]) cur++,aft[u][get(s[i])]=cur;
u=aft[u][get(s[i])]; ends[u][f].push_back(ind);
}
}
void find(string s){
int u = 0;
for(int i=0;i<s.size();i++){
if(!aft[u][get(s[i])]) return;
u=aft[u][get(s[i])];
}
if(!ends[u][0].size()){
L=n+1;
R=0; return;
}
L = ends[u][0][0],R=ends[u][0].back();
}
void find1(string s,int ind){
if(L>R) return ;
int u = 0;
for(int i=0;i<s.size();i++){
if(!aft[u][get(s[i])]) return;
u=aft[u][get(s[i])];
}
int l=0,r=ends[u][1].size(),en=-1,st=n+1;r--;
while(l<=r){
int mid=(l+r)/2;
if(ends[u][1][mid]>=L) {
st=mid;
r=mid-1;
}
else l=mid+1;
}
l=0,r=ends[u][1].size();r--;
while(l<=r){
int mid=(l+r)/2;
if(ends[u][1][mid]<=R) {
en=mid;
l=mid+1;
}
else r=mid-1;
}
if(st<=en) ans[ind]=en-st+1;
}
main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
// t=1;
cin >> n >> m;
int mx = 0;
for(int i=1;i<=n;i++){
cin >> s[i];
}
sort(s+1,s+n+1);
for(int i=1;i<=n;i++){
add(s[i],i,0);
reverse(s[i].begin(),s[i].end());
add(s[i],i,1);
}
string pref,suff;
for(int i=1;i<=m;i++){
cin>>pref>>suff;
L=n+1; R=0;
find(pref);
reverse(suff.begin(),suff.end());
find1(suff,i);
cout<<ans[i]<<" ";
}
}
Compilation message
selling_rna.cpp: In function 'void add(std::string, int, int)':
selling_rna.cpp:19:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(int i=0;i<s.size();i++){
| ~^~~~~~~~~
selling_rna.cpp: In function 'void find(std::string)':
selling_rna.cpp:28:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for(int i=0;i<s.size();i++){
| ~^~~~~~~~~
selling_rna.cpp: In function 'void find1(std::string, int)':
selling_rna.cpp:41:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i=0;i<s.size();i++){
| ~^~~~~~~~~
selling_rna.cpp: At global scope:
selling_rna.cpp:66:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
66 | main(){
| ^
selling_rna.cpp: In function 'int main()':
selling_rna.cpp:70:6: warning: unused variable 'mx' [-Wunused-variable]
70 | int mx = 0;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
199112 KB |
Output is correct |
2 |
Correct |
101 ms |
199036 KB |
Output is correct |
3 |
Correct |
101 ms |
199152 KB |
Output is correct |
4 |
Correct |
106 ms |
199108 KB |
Output is correct |
5 |
Correct |
101 ms |
199128 KB |
Output is correct |
6 |
Correct |
101 ms |
199132 KB |
Output is correct |
7 |
Correct |
106 ms |
199132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
376 ms |
313052 KB |
Output is correct |
2 |
Correct |
393 ms |
307012 KB |
Output is correct |
3 |
Correct |
329 ms |
311320 KB |
Output is correct |
4 |
Correct |
315 ms |
305948 KB |
Output is correct |
5 |
Correct |
344 ms |
325384 KB |
Output is correct |
6 |
Correct |
343 ms |
328644 KB |
Output is correct |
7 |
Correct |
166 ms |
223000 KB |
Output is correct |
8 |
Correct |
339 ms |
289692 KB |
Output is correct |
9 |
Correct |
298 ms |
274920 KB |
Output is correct |
10 |
Correct |
268 ms |
275012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
141 ms |
200716 KB |
Output is correct |
2 |
Correct |
128 ms |
200564 KB |
Output is correct |
3 |
Correct |
140 ms |
200588 KB |
Output is correct |
4 |
Correct |
124 ms |
200504 KB |
Output is correct |
5 |
Correct |
132 ms |
200604 KB |
Output is correct |
6 |
Correct |
132 ms |
200500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
199112 KB |
Output is correct |
2 |
Correct |
101 ms |
199036 KB |
Output is correct |
3 |
Correct |
101 ms |
199152 KB |
Output is correct |
4 |
Correct |
106 ms |
199108 KB |
Output is correct |
5 |
Correct |
101 ms |
199128 KB |
Output is correct |
6 |
Correct |
101 ms |
199132 KB |
Output is correct |
7 |
Correct |
106 ms |
199132 KB |
Output is correct |
8 |
Correct |
376 ms |
313052 KB |
Output is correct |
9 |
Correct |
393 ms |
307012 KB |
Output is correct |
10 |
Correct |
329 ms |
311320 KB |
Output is correct |
11 |
Correct |
315 ms |
305948 KB |
Output is correct |
12 |
Correct |
344 ms |
325384 KB |
Output is correct |
13 |
Correct |
343 ms |
328644 KB |
Output is correct |
14 |
Correct |
166 ms |
223000 KB |
Output is correct |
15 |
Correct |
339 ms |
289692 KB |
Output is correct |
16 |
Correct |
298 ms |
274920 KB |
Output is correct |
17 |
Correct |
268 ms |
275012 KB |
Output is correct |
18 |
Correct |
141 ms |
200716 KB |
Output is correct |
19 |
Correct |
128 ms |
200564 KB |
Output is correct |
20 |
Correct |
140 ms |
200588 KB |
Output is correct |
21 |
Correct |
124 ms |
200504 KB |
Output is correct |
22 |
Correct |
132 ms |
200604 KB |
Output is correct |
23 |
Correct |
132 ms |
200500 KB |
Output is correct |
24 |
Correct |
384 ms |
297288 KB |
Output is correct |
25 |
Correct |
399 ms |
297828 KB |
Output is correct |
26 |
Correct |
392 ms |
296388 KB |
Output is correct |
27 |
Correct |
341 ms |
296220 KB |
Output is correct |
28 |
Correct |
312 ms |
234320 KB |
Output is correct |
29 |
Correct |
198 ms |
212824 KB |
Output is correct |