【分析】
看了两个半小时的论文...终于懂一点了(所以我以前压根就没懂SAM啊)
张天扬刷新了我对SAM的认识(以后再也不乱找奇奇怪怪的课件了)
推荐http://download.csdn.net/detail/acvay/8950959(张天扬sam论文)
然而spoj太慢了还限制0.1s根本卡不动= =(谁每天没事了和spoj这鬼畜网站卡常数)
【代码】(再度光荣TLE)
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define ll long long
#define M(a) memset(a,0,sizeof a)
#define fo(i,j,k) for(register int i=j;i<=k;i++)
using namespace std;
const int mxn=500005;
char s[mxn];
int t[mxn],rig[mxn],f[mxn],b[mxn]; //rig数组的大小
int n,m,len,p,q,np,nq,root,tot,ans,cnt;
int son[mxn][27],pre[mxn],step[mxn];
inline void sam()
{
scanf("%s",s+1);
len=strlen(s+1);
np=root=tot=1;
fo(i,1,len)
{
int c=s[i]-'a'+1;
p=np;
step[np=(++tot)]=step[p]+1;
while(p && !son[p][c])
son[p][c]=np,p=pre[p];
if(!p)
{
pre[np]=root;
continue;
}
q=son[p][c];
if(step[q]==step[p]+1)
pre[np]=q;
else
{
step[nq=(++tot)]=step[p]+1;
fo(j,1,26) son[nq][j]=son[q][j];
pre[nq]=pre[q];
pre[q]=pre[np]=nq;
while(p && son[p][c]==q)
son[p][c]=nq,p=pre[p];
}
}
}
int main()
{
sam();
p=root;
fo(i,1,len)
{
int c=s[i]-'a'+1;
p=son[p][c],rig[p]++;
}
fo(i,1,tot) b[step[i]]++;
fo(i,1,len) b[i]+=b[i-1];
fo(i,1,tot) t[b[step[i]]--]=i; //基数排序:保证顺序从树底到树顶
for(int i=tot;i;i--) rig[pre[t[i]]]+=rig[t[i]];
fo(i,1,tot) f[step[i]]=max(f[step[i]],rig[i]);
for(int i=len;i;i--) f[i]=max(f[i+1],f[i]);
fo(i,1,len) printf("%d\n",f[i]);
return 0;
}