#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll MOD=1e9+7;
const ll N=1e6+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<60);
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()
ll trie[N][6],sz[N],ti,n,m,to[256],ans[N],mi[N],ma[N];
string s[N],pre[N],suf[N];
vector<ll> l[N],r[N];
void ins(ll id){
ll j=1;
REP(i,SZ(s[id])){
if(!trie[j][to[s[id][i]]])trie[j][to[s[id][i]]]=++ti;
++sz[j];
j=trie[j][to[s[id][i]]];
}
++sz[j];
mi[j]=(mi[j]?mi[j]:id);
ma[j]=id;
}
pll range(string &ts){
ll j=1;
REP(i,SZ(ts)){
if(!trie[j][to[ts[i]]])return mp(0,0);
j=trie[j][to[ts[i]]];
}
return mp(mi[j],ma[j]);
}
ll ask(string &ts){
ll j=1;
REP(i,SZ(ts)){
if(!trie[j][to[ts[i]]])return 0;
j=trie[j][to[ts[i]]];
}
return sz[j];
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
to['A']=1;to['G']=2;to['C']=3;to['U']=4;
cin>>n>>m;
REP1(i,n)cin>>s[i];
REP1(i,m)cin>>pre[i]>>suf[i];
sort(s+1,s+n+1);
REP1(i,n)ins(i);
REP1(i,m){
reverse(suf[i].begin(),suf[i].end());
pll tmp=range(pre[i]);
if(tmp.X)l[tmp.X-1].pb(i);
r[tmp.Y].pb(i);
}
memset(sz,0,sizeof(sz));memset(trie,0,sizeof(trie));
REP1(i,n){
reverse(s[i].begin(),s[i].end());
ins(i);
for(auto j:l[i])ans[j]-=ask(suf[j]);
for(auto j:r[i])ans[j]+=ask(suf[j]);
}
REP1(i,m)cout<<ans[i]<<"\n";
return 0;
}
Compilation message
selling_rna.cpp: In function 'void ins(ll)':
selling_rna.cpp:27:26: warning: array subscript has type 'char' [-Wchar-subscripts]
27 | if(!trie[j][to[s[id][i]]])trie[j][to[s[id][i]]]=++ti;
| ^
selling_rna.cpp:27:48: warning: array subscript has type 'char' [-Wchar-subscripts]
27 | if(!trie[j][to[s[id][i]]])trie[j][to[s[id][i]]]=++ti;
| ^
selling_rna.cpp:29:24: warning: array subscript has type 'char' [-Wchar-subscripts]
29 | j=trie[j][to[s[id][i]]];
| ^
selling_rna.cpp: In function 'pll range(std::string&)':
selling_rna.cpp:39:23: warning: array subscript has type 'char' [-Wchar-subscripts]
39 | if(!trie[j][to[ts[i]]])return mp(0,0);
| ^
selling_rna.cpp:40:21: warning: array subscript has type 'char' [-Wchar-subscripts]
40 | j=trie[j][to[ts[i]]];
| ^
selling_rna.cpp: In function 'll ask(std::string&)':
selling_rna.cpp:48:23: warning: array subscript has type 'char' [-Wchar-subscripts]
48 | if(!trie[j][to[ts[i]]])return 0;
| ^
selling_rna.cpp:49:21: warning: array subscript has type 'char' [-Wchar-subscripts]
49 | j=trie[j][to[ts[i]]];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
116 ms |
196216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
421 ms |
421880 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
145 ms |
198260 KB |
Output is correct |
2 |
Incorrect |
136 ms |
197752 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
116 ms |
196216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |