Bryce1010模板

http://acm.timus.ru/problem.aspx?space=1&num=1960

#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
struct PalindromicTree{
int fail[maxn],len[maxn],son[maxn][26];
int tot,last,n;
char s[maxn];
int newnode(int slen = 0){
memset(son[tot],0,sizeof son[tot]);
len[tot] = slen;
return tot++;
}
void init(){
n = tot = last = 0;
newnode(0);
newnode(-1);
fail[1] = fail[0] = 1;
s[n] = -1;
}
int getFail(int x){
while(s[n - len[x] - 1] != 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] + 2);
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 = 0; str[i]; ++i){
pt.extend(str[i] - 'a');
if(flag) putchar(' ');
printf("%d",pt.tot - 2);
flag = true;
}
putchar('\n');
}
return 0;
}

回文树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】1960. Palindromes and Super Abilities

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

  3. Ural 1960 Palindromes and Super Abilities

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

  4. 回文树练习 Part1

    URAL - 1960   Palindromes and Super Abilities 回文树水题,每次插入时统计数量即可. #include<bits/stdc++.h> using ...

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

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

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

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

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

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

  8. 【CF245H】Queries for Number of Palindromes(回文树)

    [CF245H]Queries for Number of Palindromes(回文树) 题面 洛谷 题解 回文树,很类似原来一道后缀自动机的题目 后缀自动机那道题 看到\(n\)的范围很小,但是 ...

  9. 【SPOJ】NUMOFPAL - Number of Palindromes(Manacher,回文树)

    [SPOJ]NUMOFPAL - Number of Palindromes(Manacher,回文树) 题面 洛谷 求一个串中包含几个回文串 题解 Manacher傻逼题 只是用回文树写写而已.. ...

随机推荐

  1. dsp端编译异常之max和min未定义

    (1)在函数之前 声明__stdcall 时 在linux 端或dsp端 linux 之前的加上宏定义 __stdcall是MS的编译器使用的只需要#define __stdcall定义一个宏就可以 ...

  2. 2016/06/02 网摘记录 svn 服务器端 客户端 安装使用

    http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2408089.html http://www.cnblogs.com/xiaobaihom ...

  3. How do I set the timeout for a JAX-WS webservice client?

    How do I set the timeout for a JAX-WS webservice client? up vote58down votefavorite 27 I've used JAX ...

  4. 数字和为sum的方法数(动态规划)

    题目描述 给定一个有n个正整数的数组A和一个整数sum,求选择数组A中部分数字和为sum的方案数.当两种选取方案有一个数字的下标不一样,我们就认为是不同的组成方案. 输入描述: 输入为两行: 第一行为 ...

  5. iOS 视图在不同View之间的切换(对于convertRect:函数的一些理解)

    可以通过以下函数完成坐标体系在不同View之间的切换,如下面是完成当前View向ParentView坐标的转换(一个矩阵转换)CGRect parentRect = [currentView conv ...

  6. #1241 : Best Route in a Grid

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个N行N列的非负整数方阵,从左上角(1,1)出发,只能向下或向右走,且不能到达值为0的方格,求出一条到达右下角的最佳 ...

  7. eclipse安装lombok和常用注解使用

    1.下载lombok.jar lombok 的官方网址:http://projectlombok.org/   2.运行lombok.jar: java -jar  D:\eclipse-luna\l ...

  8. 关于python代码的性能

    在python中性能测试是一个很难应付的任务,因为它在反复地优化,也许版本和版本之间差别很大.python中的一个主要的原则是,首先为了简单和可读性去编写代码,在程序运行后,并证明了确实有必要考虑性能 ...

  9. 【NOIP2016】 组合数问题

    [题目链接] 点击打开链接 [算法] 杨辉三角 + 二维前缀和 O(1)计算答案 [代码] #include<bits/stdc++.h> using namespace std; #de ...

  10. http监听工具Fildder

    空间管理您的位置: 51Testing软件测试网 » 雨洒泪 » 日志 中国龙,中国风,中国会变得更加强大! 力量越大,责任越大! 人的一生,会面临很多选择,但决定一个人一生的,往往就是最关键那么的一 ...