继续练习模版。
回文树。。。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int Maxn=100005;
char S[Maxn];
int len[Maxn],ans[Maxn],fail[Maxn];
int son[Maxn][26],n,st,p,c,last,i,t;
int newnode(int x){
len[st] = x;
return st++;
}
void init(){
scanf("%s",S+1);
n = strlen(S+1);
S[0] = '#';
newnode( 0 );
newnode( -1 );
fail[0] = 1;
}
int get_fail(int x,int n){
while (S[n-len[x]-1]!=S[n]) x=fail[x];
return x;
}
int main(){
//freopen("ural.in","r",stdin);
//freopen("ural.out","w",stdout);
init();
for (i=1;i<=n;i++){
c = S[i]-'a';
t = get_fail(last,i);
if (son[t][c]==0){
p = newnode( len[t]+2 );
fail[p] = son[get_fail( fail[t], i)][c];
son[t][c] = p;
ans[i]=1;
}
last = son[t][c];
}
for (i=1;i<=n;i++) ans[i]+=ans[i-1];
for (i=1;i<n;i++) printf("%d ",ans[i]);
printf("%d\n",ans[n]);
return 0;
}