After solving seven problems on Timus Online Judge with a word “palindrome” in the problem name, Misha has got an unusual ability. Now, when he reads a word, he can mentally count the number of unique nonempty substrings of this word that are palindromes.
Dima wants to test Misha’s new ability. He adds letters s 1, ..., s n to a word, letter by letter, and after every letter asks Misha, how many different nonempty palindromes current word contains as substrings. Which n numbers will Misha say, if he will never be wrong?

Input

The only line of input contains the string s 1... s n, where s i are small English letters (1 ≤ n ≤ 10 5).

Output

Output n numbers separated by whitespaces, i-th of these numbers must be the number of different nonempty substrings of prefix s 1... s i that are palindromes.

Example

input output
aba
1 2 3

按顺序每次添加一个字符,求当前本质不同的回文串的数量

回文自动机

刚开始没意识到“本质不同”,加了个统计出现次数……

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
char s[mxn];
struct Pam{
int t[mxn][];
int l[mxn],sz[mxn],fa[mxn];
int res[mxn];
int S,cnt,last;
void init(){S=cnt=last=fa[]=fa[]=;l[]=-;return;}
void add(int c,int n){
int p=last;
while(s[n-l[p]-]!=s[n])p=fa[p];
if(!t[p][c]){
int np=++cnt;l[np]=l[p]+;
int k=fa[p];
while(s[n-l[k]-]!=s[n])k=fa[k];
fa[np]=t[k][c];//fail指针
t[p][c]=np;
}
last=t[p][c];
sz[last]++;//统计出现次数
}
void solve(){
printf("%d ",cnt-);
/*
memset(res,0,sizeof res);
int ans=0;
for(int i=cnt;i;i--){
res[i]+=sz[i];
res[fa[i]]+=res[i];
ans+=res[i];
}
printf("%d ",ans);*/
return;
}
}hw;
int main(){
int i,j;
scanf("%s",s+);
int len=strlen(s+);
hw.init();
for(i=;i<=len;i++){
hw.add(s[i]-'a',i);
hw.solve();
}
return ;
}

最新文章

  1. 【codeforces 148D】 Bag of mice
  2. jasper 常用知识点总结
  3. MYSQL入门(三)
  4. MySQL基础 - 外键和约束
  5. C++ 类的静态成员详细讲解[转]
  6. 理解ATL中的一些汇编代码(通过Thunk技术来调用类成员函数)
  7. 基于Socket的UDP和TCP编程介绍
  8. An update on OS X Code Signing(OS X代码签名)
  9. hadoop - spark on yarn 集群搭建
  10. Django 后台定制自己的选择框删除函数
  11. postman连续添加多个订单&amp;jmeter快速审核添加订单
  12. IPerf——网络测试工具介绍与源码解析(1)
  13. phpcms首页替换
  14. Task使用
  15. 如何为你的树莓派安装一个WIN10系统?(非iot)
  16. python 全栈开发,Day58(bootstrap组件,bootstrap JavaScript 插件,后台模板,图表插件,jQuery插件库,Animate.css,swiper,运行vue项目)
  17. 【java编程】格式化字符串
  18. 查找被占用的端口的服务并kill掉
  19. java中使用OpenOffice
  20. GoLang 命令

热门文章

  1. scrapy 圣墟
  2. git bash学习3 -简单杂乱知识点记录
  3. 第五篇:selenium调用IE问题(Protected Mode settings are not the same for all zones)
  4. 怎样查看web软件例如apache的连接数
  5. 学习Pytbon第八天,文件的操作
  6. C++构造函数实例——拷贝构造,赋值
  7. A1058 A+B in Hogwarts (20)(20 分)
  8. 1497: [NOI2006]最大获利(最大权闭合子图)
  9. 非负矩阵分解(NMF)原理及算法实现
  10. RSA进阶之两个N的公约数