Palindromes and Super Abilities

Time Limit: 1000ms
Memory Limit: 65536KB

This problem will be judged on Ural. Original ID: 1960
64-bit integer IO format: %lld      Java class name: (Any)

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 s1, ..., sn 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 s1...sn, where si are small English letters (1 ≤ n ≤ 105).
 

Output

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

Sample Input

aba

Sample Output

1 2 3

Source

 
解题:PalindromicTree
 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct PalindromicTree{
int fail[maxn],len[maxn],son[maxn][];
int tot,last,n;
char s[maxn];
int newnode(int slen = ){
memset(son[tot],,sizeof son[tot]);
len[tot] = slen;
return tot++;
}
void init(){
n = tot = last = ;
newnode();
newnode(-);
fail[] = fail[] = ;
s[n] = -;
}
int getFail(int x){
while(s[n - len[x] - ] != s[n]) x = fail[x];
return x;
}
void extend(int c){
s[++n] = c;
int cur = getFail(last);
if(!son[cur][c]){
int x = newnode(len[cur] + );
fail[x] = son[getFail(fail[cur])][c];
son[cur][c] = x;
}
last = son[cur][c];
}
}pt;
char str[maxn];
int main(){
while(~scanf("%s",str)){
pt.init();
bool flag = false;
for(int i = ; str[i]; ++i){
pt.extend(str[i] - 'a');
if(flag) putchar(' ');
printf("%d",pt.tot - );
flag = true;
}
putchar('\n');
}
return ;
}

Ural 1960 Palindromes and Super Abilities的更多相关文章

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

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

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

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

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

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

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

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

  5. URAL 2040 Palindromes and Super Abilities 2

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

  6. 【URAL】1960. Palindromes and Super Abilities

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

  7. 回文树1960. Palindromes and Super Abilities

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

  8. URAL1960 Palindromes and Super Abilities

    After solving seven problems on Timus Online Judge with a word “palindrome” in the problem name, Mis ...

  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. Bits Equalizer UVA - 12545

    点击打开链接 #include<cstdio> #include<cstring> /* 别看错了:0能变1,1不能变0 能完成的条件是,s与t长度相等且s中0数量和?数量之和 ...

  2. Backbone学习记录(2)

    创建一个集合 1)new Backbone.Collection()方式 var user=new Backbone.Model({'name':'susan'}); var list=new Bac ...

  3. C#局部类型partial在定义实体类Model中的应用

    以前一直用继承类的方法,原来还可以这样 //例如:定义一个Person的实体类,用户ID(PersonId),姓名(Name),性别(Sex),年龄(Age),地址(Address),联系方式(Tel ...

  4. C#中this指针的用法示例

    这篇文章主要介绍了C#中this指针的用法,对初学者而言是非常重要的概念,必须加以熟练掌握,需要的朋友可以参考下. 本文实例展示了C#中this指针的用法,对于初学者进一步牢固掌握C#有很大帮助,具体 ...

  5. AJPFX总结java 中类的创建和使用

    //面向对象中类的创建和 调用 ============================================================= 类的使用: 类的使用分为两个动作:创建对象与 ...

  6. dubbo系列--重要概念介绍

    dubbo架构图 节点角色说明 整体设计 proxyFactory:就是为了获取一个接口的代理类,例如获取一个远程接口的代理.它有2个方法,代表2个作用 getInvoker:针对server端,将服 ...

  7. (5)《Head First HTML与CSS》学习笔记---布局与定位

    层叠与CSS的权重判断 1.要理解层叠,除了前面的内容外还差最后一个知识点.你已经知道如何使用多个样式表来更好地组织你的样式,或者支持不同类型的设备.不过实际上用户访问你的页面时还有另外一些样式表. ...

  8. SqlServer2005使用top 100 PERCENT 无法排序的问题

    由于公司提供的分页控件需要我使用top子句,而且有必要将查询到的记录全部取出,确发现不能排序,sql语句如下: SELECT TOP 15 * FROM( SELECT TOP (100) PERCE ...

  9. php同时查询两个表的数据

    业务环境,表一 会员等级表, 表二会员表, 有一个字段是相同的 会员等级ID level 在会员的显示页面要直接显示会员的会员等级名称,不是等级ID. 1.同时查询两个表 2.表设置别名, selec ...

  10. Python3中的输入输出

    input()函数 我们可以通过Python3解释器查看Python3中input()的含义: >>> type(input) <class 'builtin_function ...