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. device not managed by NetworkManager

    Bringing up interface eth0:Error:Connection activation failed:Device not managed by  NetworkManager ...

  2. 在HDInsight中的Hadoop介绍

    在HDInsight中的Hadoop介绍 概览 Azure的HDInsight是,部署和规定的Apache™Hadoop®集群在云中,提供用于管理,分析和大数据报告软件框架中的服务. 大数据 数据被描 ...

  3. html的书写规范,有哪些注意点

    1.最开始的声明格式与编码格式,注意html5与和html4.0的区别,注意对不同浏览器的渲染作用: 2.<head></head>标签中的相关内容的编写: 3.确保引入的jq ...

  4. 如何使用git 生成patch 和打入patch【转】

    本文转载自:http://blog.csdn.net/liuhaomatou/article/details/54410361 平时我们在使用git 管理项目的时候,会遇到这样一种情况,那就是客户使用 ...

  5. 利用Swoole实现PHP+websocket直播,即使通讯

    websocket Websocket只是一个网络通信协议,就像 http.ftp等都是网络通信的协议一样:相对于HTTP这种非持久的协议来说,Websocket是一个持久化网络通信的协议: WebS ...

  6. 一步一步学Silverlight 2系列(28):图片处理

    概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...

  7. POJ 1236 Network of Schools (校园网)

    Description 一些学校连入一个电脑网络.那些学校已订立了协议:每个学校都会给其它的一些学校分发软件(称作“接受学校”).注意如果 B 在 A 学校的分发列表中,那么 A 不必也在 B 学校的 ...

  8. C++ main函数中参数argc和argv含义及用法

    argc 是 argument count的缩写,表示传入main函数的参数个数: argv 是 argument vector的缩写,表示传入main函数的参数序列或指针,并且第一个参数argv[0 ...

  9. 在Service里调用AlertDialog

    用常规的方法在AlertDialog的时候,会报错,大意是「can not add window in this view」. 原因是Service是没有界面的,只有Activity才能添加界面. 解 ...

  10. [laravel]请求处理

    请求进入 public/index.php 文件. bootstrap/start.php 文件创建应用程序对象并检测环境. 内部的 framework/start.php 文件配置相关设置并加载服务 ...