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

Description

Dima adds letters s1, …, sn one by one to the end of a word. After each letter, he asks Misha to tell him how many new palindrome substrings appeared when he added that letter. Two substrings are considered distinct if they are different as strings. Which n numbers will be said by Misha if it is known that he is never wrong?

Input

The input contains a string s1 … sn consisting of letters ‘a’ and ‘b’ (1 ≤ n ≤ 5 000 000).

Output

Print n numbers without spaces: i-th number must be the number of palindrome substrings of the prefix s1 … si minus the number of palindrome substrings of the prefix s1 … si−1. The first number in the output should be one.
 
Sample Input
abbbba
 
Sample Output
111111

Notes

We guarantee that jury has C++ solution which fits Time Limit at least two times. We do not guarantee that solution on other languages exists (even Java).

Source

Problem Author: Mikhail Rubinchik (prepared by Kirill Borozdin) 
 
解题:PalindromicTree
 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct PalindromicTree{
struct node{
int son[],f,len;
void init(int len){
memset(son,,sizeof son);
this->len = len;
}
}e[maxn];
int tot,last,n;
char s[maxn];
int newnode(int len = ){
e[tot].init(len);
return tot++;
}
int getFail(int x){
while(s[n - e[x].len - ] != s[n]) x = e[x].f;
return x;
}
void init(){
last = tot = n = ;
newnode();
newnode(-);
e[].f = ;
s[n] = -;
}
bool extend(int c){
s[++n] = c;
int cur = getFail(last);
bool isExtend = e[cur].son[c] == ;
if(!e[cur].son[c]){
int newson = newnode(e[cur].len + );
e[newson].f = e[getFail(e[cur].f)].son[c];
e[cur].son[c] = newson;
}
last = e[cur].son[c];
return isExtend;
}
}pt;
char str[maxn];
int main(){
while(gets(str)){
pt.init();
for(int i = ; str[i]; ++i){
if(pt.extend(str[i] - 'a')) putchar('');
else putchar('');
}
putchar('\n');
}
return ;
}
 

URAL 2040 Palindromes and Super Abilities 2的更多相关文章

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

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

  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 1960 Palindromes and Super Abilities

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

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

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

  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. URAL1960 Palindromes and Super Abilities

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

  8. 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 ...

  9. 回文树1960. Palindromes and Super Abilities

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

随机推荐

  1. 转-sql之left join、right join、inner join的区别

    left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录inner join(等值连接) 只 ...

  2. [在读]functional javascript

    讲javascript函数化编程的一本书,逛淘宝正好看到有一家卖英文书的,顺手就买了,目前搁置.

  3. AJPFX总结private关键字

    private关键字        什么是private关键字?                它是一个修饰符,代表私有的意思,它可以修饰成员变量和成员方法 private关键字的特点?        ...

  4. 亲身经历,Java面试题整理

    博主在2015年暑期参加过一些Java开发工程师实习的面试和笔试,在此将重点整理出来,以供大家学习. 资料1: 一.单继承 1.1Java类是否支持多重继承? 答:继承的基本原则是: 子类继承父类的所 ...

  5. android控件之webview和js与java交互

    首先添加权限:<uses-permission android:name="android.permission.INTERNET"/> 布局文件: <Relat ...

  6. Android利用已有控件实现自定义控件

    Android控件的基本介绍及使用自定义控件的意义         Android 本身提供了很多控件,自定义控件在android中被广泛运用,自定义控件给了我们很大的方便.比如说,一个视图为imag ...

  7. spring中junit 提示Failed to load ApplicationContext

    错误提示: 1:java.lang.IllegalStateException: Failed to load ApplicationContext 2:Error creating bean wit ...

  8. Win10本地搭建Apache+PHP运行环境

    微软全新操作系统Windows10在190个国家和地区正式同步上市,正版Windows7.Windows8.1用户均可在一年内免费升级.介绍一下在升级后的Windwos10系统上安装及配置Apache ...

  9. c++调用com口操作autocad

    #include "stdafx.h" #include <atlcomcli.h> #import "D:\\C++test\\FirstCom\\Rele ...

  10. jquery--cookie应用

    示例:发送手机验证码 防止页面刷新后,发送验证码按钮重置 注:橙色部分为后增加代码,为防止验证码等待期间用户退出或者切换到其他页面以至于很久之后回到当前页面倒计时还在的问题,加入时间对比,记录用户发送 ...