你说得对,这是啥波题.
但是有个啥波 wa on 4~11.
你妈的,不会又是原板子题就写的错的吧 /qd
#include<bits/stdc++.h>
using namespace std;
string a[205];
int n,trie[1000005][27],fail[1000005],c,ans[205],f[205],ind[1000005];
vector<int>ed[1000005];
void ins(string s,int id)
{
int p=0;
for(int i=0;i<s.size();i++)
{
if(!trie[p][s[i]-97]) trie[p][s[i]-97]=++c;
p=trie[p][s[i]-97];
}
ed[p].push_back(id);
}
void acam()
{
queue<int>q;
for(int i=0;i<27;i++)
{
if(!trie[0][i]) continue;
fail[trie[0][i]]=0;
q.push(trie[0][i]);
}
while(!q.empty())
{
int x=q.front();
q.pop();
for(int i=0;i<27;i++)
{
if(trie[x][i])
{
fail[trie[x][i]]=trie[fail[x]][i];
ind[fail[trie[x][i]]]++;
q.push(trie[x][i]);
}
else trie[x][i]=trie[fail[x]][i];
}
}
}
void qry(string s)
{
int p=0;
for(int i=0;i<s.size();i++)
{
p=trie[p][s[i]-97];
f[p]++;
}
}
void topo()
{
queue<int>q;
for(int i=1;i<=c;i++)
{
if(ind[i]) continue;
q.push(i);
}
while(!q.empty())
{
int x=q.front();
q.pop();
for(auto i:ed[x]) ans[i]=f[x];
f[fail[x]]+=f[x];
if(!--ind[fail[x]]) q.push(fail[x]);
}
}
int main()
{
ios::sync_with_stdio(0);
cin>>n;
string s="";
for(int i=1;i<=n;i++)
{
cin>>a[i];
s+=a[i]+"{";
ins(a[i],i);
}
fail[0]=0;
acam();
qry(s);
topo();
for(int i=1;i<=n;i++) cout<<ans[i]<<endl;
return 0;
}