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 ;
}

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. jquery的ajax请求

    加载页面内容,如果不加选择器,会加载整个页面内容 加选择器会获取选择器内容 例如: <script> //可以获取json格式的文件 $.ajax({ type:"get&quo ...

  2. JavaScript获取时间戳与时间戳转化

    第一种方法(精确到秒): var timestamp1 = Date.parse( new Date()); 第二种方法(精确到毫秒): var timestamp2 = ( new Date()). ...

  3. 《转载》ASP动态iframe

    原文:[ASP.NET]关于iframe的两个技巧 最近在给朋友写个网站,虽然不大,但是也碰到了一些问题.这篇就为解决ASP.NET中关于IFRAME的两个很现实的问题提供解决方法.PS:呵呵,又做了 ...

  4. Bzoj 1081 [Ahoi2009] chess 中国象棋

    bzoj 1081 [Ahoi2009] chess 中国象棋 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1801 状态比较难设,的确 ...

  5. python中函数返回多个值

    用ipython运行情况如下: # 新建一个函数 In [1]: def nums(): ...: a = 11 ...: b = 22 ...: c = 33 ...: return [a,b,c] ...

  6. cut(树形DP)

    Description F大爷热爱切树.今天他找到一棵黑白树,不到两秒钟,F大爷就把这棵树切掉了.已知原先树上共n个点,每个点都是黑点或者白点,F大爷切去若干条边后,分成的若干个连通子树中每块恰有一个 ...

  7. Oracle数据库迁移--->从Windows到Linux

    I did a practice to migrate the oracle database from windows to linux operation system. The followin ...

  8. 【Unique Paths II】cpp

    题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...

  9. IOS开发学习笔记027-UITableView 使用模型对象

    1.模型对象 2.单组数据的显示 1.模型对象 继续优化上一个程序 上一次用到字典,但是坏处多多.这里将这些数据封装到类中. 这就是MVC中得模型,模型就是数据的显示结构 新建一个类,添加几个属性和一 ...

  10. python-day5-格式化输入

    python格式化输入包含'%'调用,及format方法 使用‘%’进行格式化输出 #最简单的字符串传参 tpl='i am %s '%'alex' >>>i am alex #字符 ...