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. 笔记整理--LibCurl开发

    LibCurl开发_未了的雨_百度空间 - Google Chrome (2013/7/26 21:11:15) LibCurl开发 一:LibCurl 编程流程1.调用curl_global_ini ...

  2. org.apache.flume.EventDeliveryException: NettyAvroRpcClient { host: hadoop1, port: 41414 }: Failed to send event

    org.apache.flume.EventDeliveryException: NettyAvroRpcClient { host: hadoop1, port: 41414 }: Failed t ...

  3. 深入解析Hibernate核心接口

    Hibernate有很多值得学习的地方,这里我们主要介绍Hibernate核心接口,包括介绍SessionFactory接口.Query和Criteria接口等方面. Session 接口对于Hibe ...

  4. 「翻译」Unity中的AssetBundle详解(二)

    为AssetBundles准备资源 使用AssetBundles时,您可以随意将任何Asset分配给所需的任何Bundle.但是,在设置Bundles时,需要考虑一些策略.这些分组策略可以使用到任何你 ...

  5. XMLHttp.send()不传参时必须传null吗?

    xmlhttp的send是传递参数用的,但是只有在使用post方式提交请求的时候才有用如下:xmlhttp.open("post",url,true); ...xmlhttp.se ...

  6. SpringBoot使用logback日志记录

    在resources里的配置文件: logback-spring.xml <?xml version="1.0" encoding="UTF-8" ?&g ...

  7. codeforces C. Magic Formulas 解题报告

    题目链接:http://codeforces.com/problemset/problem/424/C 题目意思:给出 n 个数:p1, p2, ..., pn,定义: q1 = p1 ^ (1 mo ...

  8. 一步一步学Silverlight 2系列(10):使用用户控件

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

  9. 全排列 STL

    #include<iostream> #include<algorithm> #include<stdio.h> using namespace std; int ...

  10. maven实战(6)-- pom.xml的编写

    pom.xml中可以编写的东西确实挺多的,经常看到别人写的pom文件中出现了一些没见过plugin或properties等等,不知有何作用,其实很简单,只要参看maven的官方文档即可:http:// ...