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
  1. aba
  1. 1 2 3

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

回文自动机

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

  1. /*by SilverN*/
  2. #include<algorithm>
  3. #include<iostream>
  4. #include<cstring>
  5. #include<cstdio>
  6. #include<cmath>
  7. #include<vector>
  8. using namespace std;
  9. const int mxn=;
  10. int read(){
  11. int x=,f=;char ch=getchar();
  12. while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
  13. while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
  14. return x*f;
  15. }
  16. char s[mxn];
  17. struct Pam{
  18. int t[mxn][];
  19. int l[mxn],sz[mxn],fa[mxn];
  20. int res[mxn];
  21. int S,cnt,last;
  22. void init(){S=cnt=last=fa[]=fa[]=;l[]=-;return;}
  23. void add(int c,int n){
  24. int p=last;
  25. while(s[n-l[p]-]!=s[n])p=fa[p];
  26. if(!t[p][c]){
  27. int np=++cnt;l[np]=l[p]+;
  28. int k=fa[p];
  29. while(s[n-l[k]-]!=s[n])k=fa[k];
  30. fa[np]=t[k][c];//fail指针
  31. t[p][c]=np;
  32. }
  33. last=t[p][c];
  34. sz[last]++;//统计出现次数
  35. }
  36. void solve(){
  37. printf("%d ",cnt-);
  38. /*
  39. memset(res,0,sizeof res);
  40. int ans=0;
  41. for(int i=cnt;i;i--){
  42. res[i]+=sz[i];
  43. res[fa[i]]+=res[i];
  44. ans+=res[i];
  45. }
  46. printf("%d ",ans);*/
  47. return;
  48. }
  49. }hw;
  50. int main(){
  51. int i,j;
  52. scanf("%s",s+);
  53. int len=strlen(s+);
  54. hw.init();
  55. for(i=;i<=len;i++){
  56. hw.add(s[i]-'a',i);
  57. hw.solve();
  58. }
  59. return ;
  60. }

URAL1960 Palindromes and Super Abilities的更多相关文章

  1. URAL 2040 Palindromes and Super Abilities 2 (回文自动机)

    Palindromes and Super Abilities 2 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/E Descr ...

  2. Ural 2040. Palindromes and Super Abilities 2 回文自动机

    2040. Palindromes and Super Abilities 2 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2040 ...

  3. 回文树(回文自动机) - URAL 1960 Palindromes and Super Abilities

     Palindromes and Super Abilities Problem's Link: http://acm.timus.ru/problem.aspx?space=1&num=19 ...

  4. URAL 2040 Palindromes and Super Abilities 2(回文树)

    Palindromes and Super Abilities 2 Time Limit: 1MS   Memory Limit: 102400KB   64bit IO Format: %I64d ...

  5. Ural 1960 Palindromes and Super Abilities

    Palindromes and Super Abilities Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged ...

  6. URAL 2040 Palindromes and Super Abilities 2

    Palindromes and Super Abilities 2Time Limit: 500MS Memory Limit: 102400KB 64bit IO Format: %I64d &am ...

  7. 【URAL】1960. Palindromes and Super Abilities

    http://acm.timus.ru/problem.aspx?space=1&num=1960 题意:给一个串s,要求输出所有的s[0]~s[i],i<|s|的回文串数目.(|s|& ...

  8. 回文树1960. Palindromes and Super Abilities

    Bryce1010模板 http://acm.timus.ru/problem.aspx?space=1&num=1960 #include <bits/stdc++.h> usi ...

  9. Ural2040:Palindromes and Super Abilities(离线&manecher算法)

    Dima adds letters s1, …, sn one by one to the end of a word. After each letter, he asks Misha to tel ...

随机推荐

  1. js获取整型数组最大值、最小值、平均值

    ---恢复内容开始--- let values = [];//数组(整型数字) //获取数组最大值function arrMaxNum(arr){ var maxNum = null; for (va ...

  2. 2018年江西理工大学C语言程序设计竞赛(高级组) 三角平方数

    题目描述 三角数:形如图a,圆点摆放成等边三角形的数字,则为三角数. (图a) 平方数:形如图b,小方块摆放成正方形的数字,则为平方数. (图b) 那么如果一个数字既是三角形数又是平方数,则称为三角平 ...

  3. (PowerDesigner&Sqlite)PD中设计完表后,将其导入数据库中

    本人连接过SQLServer跟SQLite Ⅰ.SQLServer,百度,转一下:http://jingyan.baidu.com/article/7f766daf465e9c4101e1d0d5.h ...

  4. day 16 JS DOM 继续

    为什么有jquey了还学DOM  ? 因为JQuey 是大而全,可能有10k 但是我们用到的只有1k  网站小没事,网站大流量就是问题 所以大网站都是自己用DOM 实现一个类似于JQuey 的适合自己 ...

  5. luogu3195 [HNOI2008]玩具装箱TOY

    懒得写 #include <iostream> #include <cstdio> using namespace std; typedef long long longliv ...

  6. kubernetes大概的工作原理

    先放一张Kubernetes的架构图: 整体来看,是一个老大,多个干活的这种结构,基本上所有的分布式系统都是这样,但是里面的组件名称就纷繁复杂,下面将一一解析. 1.元数据存储与集群维护 作为一个集群 ...

  7. Couchbase I

    Couchbase第一印象(架构特性) 面向文档 保存的字节流总有一个 DOCUMENT ID(Object_ID) 高并发性,高灵活性,高拓展性,容错性好 面向文档的集群存储系统 每个文档用一个唯一 ...

  8. IOS开发学习笔记008-预处理

    预处理 1.宏定义 2.条件编译 3.文件包含 注意: 1.所有预处理都是以#开头,并且结尾不用分号. 2.宏名一般用大写字母,以便与变量名区别开来,但用小写也没有语法错误 3.作用域也是从定义到代码 ...

  9. 项目实战:CRM客户关系管理系统开发

    21-CRM第一节内容概要 21.1 Stark组件介绍:实现基本的增删改查+自定义复杂操作: 21.2 单例模式:最简单的单例模式: 21.3 路由系统(分发): 21.4 制作启动文件-Djang ...

  10. vue tradingView(二)

    tradingView 一些配置问题 tradingView 一些配置问题 javascript Demo_Hu 4月17日提问 · 4月17日更新 9 关注 1 收藏,993 浏览 问题对人有帮助, ...