Submission #288838

#TimeUsernameProblemLanguageResultExecution timeMemory
288838YJUSelling RNA Strands (JOI16_selling_rna)C++14
35 / 100
430 ms421368 KiB
#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 (stderr)

selling_rna.cpp: In function 'll to(char)':
selling_rna.cpp:29:1: warning: control reaches end of non-void function [-Wreturn-type]
   29 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...