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. 优先队列 POJ 2431 Expedition

    题目传送门 题意:一辆卡车要行驶L长度,初始有P油,每行驶一个单位长度消耗一单位油.有n个加油站可以加油,问最少加油几次才能行驶L长度,如果不能输出-1 分析:按照挑战书的解法,每走到一个加油站相当于 ...

  2. Hadoop的ChainMapper和ChainReducer使用案例(链式处理)(四)

    不多说,直接上干货!      Hadoop的MR作业支持链式处理,类似在一个生产牛奶的流水线上,每一个阶段都有特定的任务要处理,比如提供牛奶盒,装入牛奶,封盒,打印出厂日期,等等,通过这样进一步的分 ...

  3. CF982C Cut 'em all!

    思路: 在深搜过程中,贪心地把树划分成若干个连通分支就可以了.划分的条件是某个子树有偶数个节点.注意到在一次划分之后并不需要重新计数,因为一个数加上一个偶数并不影响这个数的奇偶性. 实现: #incl ...

  4. iOS 利用UIWebView与JavaScript交互的最简单办法

    这里说的是针对iOS的!并且方法很简单!!并且验证可行的!!! 1, UIWebView调用 JavaScript 的函数: NSString* strValue = [webView stringB ...

  5. 做OJ项目时遇到的坑

    1.js代码写在Dom加载前,导致highcharts在ie8能够显示,而ie高版本和其他浏览器不能显示 我的理解:由于IE8和其他浏览器的js解析机制不同,ie8是在等dom全部加载完才开始执行js ...

  6. 如何在Ubuntu里安装Helm

    Helm是什么?在战网上玩过暗黑破坏神2代的程序员们应该还记得,Helm是国度的意思. 而在计算机领域,Helm是什么? Helm是Kubernetes的一个包管理工具,有点像nodejs的npm,U ...

  7. python json.loads json.dumps的区别

    json.loads() 是将字符串传化为字典 json.dumps () 是将字典转化为字符串 >>> dict = "{8:'bye', 'you':'coder'}& ...

  8. The MySQL server is running with the –secure-file-priv

    show variables like '%secure%'; 将文件导出路径更改为查询到的secure-file-priv路径下 select * from table where column = ...

  9. springmvc下载那些事

    文件的上传下载一般在项目中还是非常实用的,此处专门整理一下文件的下载,至于文件的上传实现将在后续中补上.文件的下载多用于模板文件的下载,这在项目中用的还是挺多的.今天用到了就整理出来了,以供搬运工们借 ...

  10. Xcode导入第三方库图文

    Three20这个与facebook亲戚的开源库是蜚声iPhone开发界,很多App都有它的影子,主要是其真得是功能强大.那么如何将Three20库添加到自己的项目中应用呢?一种是Python命令方式 ...