#include<cstdio>
#include<vector>
#include<cstring>
#include<map>
using namespace std;
#define int long long
const int N=1000010;
int n,i,j,tot=1,slink[N*2],trans[N*2][26],endpos[N*2][2],maxlen[N*2],pre[N*2][2];
int top,fir[N*2],ne[N*4],la[N*4],to[N*4],BLOCK,q,l,r;
const int base1=13,base2=97,ha1=1e7+19,ha2=1e7+79;
char s[N],t[N];
int ans;
int newstate(int mx,int* _trans,int _slink)
{
tot++,maxlen[tot]=mx,slink[tot]=_slink;
if(_trans)for(int i=0;i<26;i++)trans[tot][i]=_trans[i];
else for(int i=0;i<26;i++)trans[tot][i]=-1;
return tot;
}
int addchar(int now,char ch,int which)
{
int c=ch-'a',v=now;
int NEW=newstate(maxlen[now]+1,NULL,1);
while(v!=-1&&trans[v][c]==-1)trans[v][c]=NEW,v=slink[v];
if(v==-1)
{
slink[NEW]=1;
return NEW;
}
int x=trans[v][c];
if(maxlen[v]+1==maxlen[x])
{
slink[NEW]=x;
return NEW;
}
int y=newstate(maxlen[v]+1,trans[x],slink[x]);
slink[x]=slink[NEW]=y;
while(v!=-1&&trans[v][c]==x)
{
trans[v][c]=y;
v=slink[v];
}
return NEW;
}
vector<int> hh1,hh2,hh3,hh4;
map<int,int> mp;
void add(int x,int y)
{
top++,to[top]=y;
if(fir[x]==0)fir[x]=top;else ne[la[x]]=top;
la[x]=top;
}
void dfs(int x)
{
for(int i=fir[x];i;i=ne[i])
dfs(to[i]),endpos[x][0]+=endpos[to[i]][0],endpos[x][1]+=endpos[to[i]][1];
endpos[x][0]+=pre[x][0],endpos[x][1]+=pre[x][1];
if(endpos[x][0]==0)ans+=(maxlen[x]-maxlen[slink[x]]);
}
main()
{
scanf("%s",s+1),n=strlen(s+1);BLOCK=700;
memset(trans[1],-1,sizeof trans[1]);slink[1]=-1;
int LA=1;
for(i=1;i<=n;i++)LA=addchar(LA,s[i],0),pre[LA][0]++;
scanf("%lld",&q);
while(q--)
{
scanf("%s",t+1);scanf("%lld%lld",&l,&r);int len=strlen(t+1);ans=0;
mp.clear();
if(len<BLOCK)
{
int now;
for(i=1;i<=len;i++)
{
now=1;int H1=0;
for(j=i;j<=len;j++)
{
H1=H1*base1+t[j];
if(now!=-1)now=trans[now][t[j]-'a'];
if(now==-1)
{
if(mp[H1]==0)
ans++,mp[H1]=1;
}
}
}
printf("%lld\n",ans);
}else
{
int LA=1;
for(i=1;i<=len;i++)LA=addchar(LA,t[i],1),pre[LA][1]++;
for(i=2;i<=tot;i++)
add(slink[i],i);
dfs(1);
printf("%lld\n",ans);
memset(fir,0,sizeof fir);
memset(ne,0,sizeof ne);
memset(to,0,sizeof to);
memset(la,0,sizeof la);top=0;
memset(trans,0,sizeof trans);
memset(trans[1],-1,sizeof trans[1]);
memset(slink,0,sizeof slink);
memset(endpos,0,sizeof endpos);
memset(pre,0,sizeof pre);
tot=1;
slink[1]=-1;
LA=1;
for(i=1;i<=n;i++)LA=addchar(LA,s[i],0),pre[LA][0]++;
}
}
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 785.5 ms | 1 MB + 296 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #2 | 781.639 ms | 1 MB + 580 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #3 | 814.957 ms | 1 MB + 584 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #4 | 4 s | 579 MB + 944 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #5 | 4 s | 579 MB + 944 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #6 | 500.264 ms | 592 MB + 864 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #7 | 501.017 ms | 592 MB + 872 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #8 | 2.977 s | 583 MB + 444 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #9 | 4 s | 583 MB + 880 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #10 | 4 s | 584 MB + 788 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #11 | 4 s | 585 MB + 148 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #12 | 4 s | 587 MB + 136 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #13 | 4 s | 586 MB + 516 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #14 | 4 s | 591 MB + 68 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #15 | 4 s | 587 MB + 920 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #16 | 4 s | 595 MB + 324 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #17 | 4 s | 589 MB + 316 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #18 | 4 s | 591 MB + 972 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #19 | 4 s | 593 MB + 252 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #20 | 4 s | 594 MB + 232 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #21 | 4 s | 595 MB + 380 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #22 | 4 s | 595 MB + 432 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #23 | 4 s | 595 MB + 464 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #24 | 4 s | 595 MB + 192 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #25 | 4 s | 595 MB + 548 KB | Time Limit Exceeded | Score: 0 | 显示更多 |