回文字动机每次新建点就相当于增加了一种回文串。
#include<bits/stdc++.h>
using namespace std;
int n, tot, las, fil[100005], nx[100005][30], len[100005];
int rt, now, sum;
char s[100005];
int newnode(int l) {
len[tot] = l;
return tot++;
}
int getfil(int x, int n) {
while(s[n - len[x] - 1] != s[n]) x = fil[x];
return x;
}
int main() {
cin >> (s + 1);
newnode(0); newnode(-1);
s[0] = -1;
fil[0] = 1;
for(n = 1; s[n]; ++n) {
s[n] -= 'a';
rt = getfil(las, n);
if(!nx[rt][s[n]]) {
now = newnode(len[rt] + 2);
fil[now] = nx[getfil(fil[rt], n)][s[n]];
nx[rt][s[n]] = now;
++sum;
}
las = nx[rt][s[n]];
cout << sum << ' ';
}
return 0;
}