我用Z value吃了TLE
#include<bits/stdc++.h>
using namespace std;
int main(){ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;
string s,ss,t;
cin>>s>>n;
while(n--){
int z[200039]={},i,j,k,sum=0,l=1;
cin>>ss,t=ss+"$"+s+"*";
for(i=1;i<t.size();++i){
if(l+z[l]<=i){
j=0,k=i;
while(t[k]==t[j])++j,++k;
z[i]=j;
if(z[l]+l<z[i]+i)l=i;
}
else if(l+z[l]>i&&l+z[l]>i+z[i-l])z[i]=z[i-l];
else if(l+z[l]>i&&l+z[l]==i+z[i-l]){
j=z[i-l],k=l+z[l];
while(t[k]==t[j])++j,++k;
z[i]=j;
if(z[i]+i>z[l]+l)l=i;
}
else if(l+z[l]>i&&l+z[l]<i+z[i-l])z[i]=z[l]-i+l;
if(z[i]==ss.size())++sum;
}
cout<<sum<<"\n";
}
}