#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][5],sz[N],ti=1,n,m,ans[N],mi[N],ma[N];
string s[N],pre[N],suf[N];
vector<ll> l[N],r[N];
ll to(char c){
if(c=='A')return 1;
if(c=='G')return 2;
if(c=='C')return 3;
if(c=='U')return 4;
}
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;
mi[j]=(mi[j]?mi[j]:id);
ma[j]=id;
++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);
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 'll to(char)':
selling_rna.cpp:29:1: warning: control reaches end of non-void function [-Wreturn-type]
29 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
188280 KB |
Output is correct |
2 |
Correct |
119 ms |
188280 KB |
Output is correct |
3 |
Correct |
118 ms |
188280 KB |
Output is correct |
4 |
Correct |
116 ms |
188156 KB |
Output is correct |
5 |
Correct |
117 ms |
188152 KB |
Output is correct |
6 |
Correct |
116 ms |
188280 KB |
Output is correct |
7 |
Correct |
115 ms |
188280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
430 ms |
421368 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
142 ms |
189964 KB |
Output is correct |
2 |
Correct |
139 ms |
189560 KB |
Output is correct |
3 |
Correct |
141 ms |
189684 KB |
Output is correct |
4 |
Correct |
138 ms |
189432 KB |
Output is correct |
5 |
Correct |
136 ms |
189304 KB |
Output is correct |
6 |
Correct |
146 ms |
189688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
188280 KB |
Output is correct |
2 |
Correct |
119 ms |
188280 KB |
Output is correct |
3 |
Correct |
118 ms |
188280 KB |
Output is correct |
4 |
Correct |
116 ms |
188156 KB |
Output is correct |
5 |
Correct |
117 ms |
188152 KB |
Output is correct |
6 |
Correct |
116 ms |
188280 KB |
Output is correct |
7 |
Correct |
115 ms |
188280 KB |
Output is correct |
8 |
Runtime error |
430 ms |
421368 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |