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

题面

洛谷

求一个串中包含几个回文串

题解

Manacher傻逼题

只是用回文树写写而已。。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
#define RG register
#define MAX 10000
inline int read()
{
RG int x=0,t=1;RG char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=-1,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return x*t;
}
int n;
char s[MAX];
int size[MAX];
struct PT
{
struct Node
{
int son[26];
int ff,len;
}t[MAX];
int last,tot;
void init()
{
t[tot=1].len=-1;
t[0].ff=t[1].ff=1;
}
void extend(int c,int n,char *s)
{
int p=last;
while(s[n-t[p].len-1]!=s[n])p=t[p].ff;
if(!t[p].son[c])
{
int v=++tot,k=t[p].ff;
while(s[n-t[k].len-1]!=s[n])k=t[k].ff;
t[v].len=t[p].len+2;
t[v].ff=t[k].son[c];
t[p].son[c]=v;
}
++size[last=t[p].son[c]];
}
void Calc()
{
for(int i=tot;i;--i)size[t[i].ff]+=size[i];
}
}PT;
int ans;
int main()
{
PT.init();
scanf("%s",s+1);
n=strlen(s+1);
for(int i=1;i<=n;++i)PT.extend(s[i]-97,i,s);
PT.Calc();
for(int i=2;i<=PT.tot;++i)ans+=size[i];
printf("%d\n",ans);
return 0;
}

【SPOJ】NUMOFPAL - Number of Palindromes(Manacher,回文树)的更多相关文章

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

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

  2. CF245H Queries for Number of Palindromes(回文树)

    题意翻译 题目描述 给你一个字符串s由小写字母组成,有q组询问,每组询问给你两个数,l和r,问在字符串区间l到r的字串中,包含多少回文串. 输入格式 第1行,给出s,s的长度小于5000 第2行给出q ...

  3. 【Aizu2292】Common Palindromes(回文树)

    [Aizu2292]Common Palindromes(回文树) 题面 Vjudge 神TMD日语 翻译: 给定两个字符串\(S,T\),询问\((i,j,k,l)\)这样的四元组个数 满足\(S[ ...

  4. CF17E Palisection(manacher/回文树)

    CF17E Palisection(manacher/回文树) Luogu 题解时间 直接正难则反改成求不相交的对数. manacher求出半径之后就可以差分搞出以某个位置为开头/结尾的回文串个数. ...

  5. BZOJ.2565.[国家集训队]最长双回文串(Manacher/回文树)

    BZOJ 洛谷 求给定串的最长双回文串. \(n\leq10^5\). Manacher: 记\(R_i\)表示以\(i\)位置为结尾的最长回文串长度,\(L_i\)表示以\(i\)开头的最长回文串长 ...

  6. SPOJ Number of Palindromes(回文树)

    Number of Palindromes Time Limit: 100MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu ...

  7. SP7586 NUMOFPAL - Number of Palindromes 解题报告

    SP7586 NUMOFPAL - Number of Palindromes 题意翻译 求一个串中包含几个回文串 输入输出格式 输入格式: The string S. 输出格式: The value ...

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

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

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

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

随机推荐

  1. python爬虫(3)——SSL证书与Handler处理器

    一.SSL证书问题 上一篇文章,我们创建了一个小爬虫,下载了上海链家房产的几个网页.实际上我们在使用urllib联网的过程中,会遇到证书访问受限的问题. 处理HTTPS请求SSL证书验证,如果SSL证 ...

  2. yii2 源码分析Behavior类分析 (四)

    Behavior类是所有事件类的基类,它继承自object类 Behavior类的前面注释描述大概意思: * Behavior类是所有事件类的基类 * * 一个行为可以用来增强现有组件的功能,而不需要 ...

  3. [HNOI2008] GT考试

    [HNOI2008] GT考试 标签 : DP 矩阵乘法 题目链接 题意 n位数中不出现一个子串的方案数. 题解 \(设dp[i][j]\)为前i位匹配到j时的合法方案数.(所谓合法,就是不能有别的匹 ...

  4. 可拖动布局之Gridster

    看过bootstrap可视化布局系统的人是不是都会对页面元素的拖拽有着很大的兴趣?下面呢,楼主就给大家讲两个楼主知道的拖拽小插件吧. 一.gridster 1.了解gridster 后续官网:http ...

  5. springMvc学习笔记一

    什么是springmvc  springmvc就是spring框架的一个模块 所以springmvc与spring之间无需通过中间整合层进行整合的. springmvc又是基于mvc的web框架 mv ...

  6. Python基础——for/while循环

    Python版本:3.6.2  操作系统:Windows  作者:SmallWZQ 上学期间,常常遇到这样的情景:为了惩罚学生,老师会说:"XXX,你先去操场上跑10圈再回来继续反省.&qu ...

  7. 高并发WEB网站优化方案

    一.什么是高并发在互联网时代,所讲的并发.高并发,通常是指并发访问,也就是在某个时间点,有多少个访问同时到来.比如,百度首页同时有1000个人访问,那么也就是并发为1000.通常一个系统的日PV在千万 ...

  8. day3(while、流程控制)

    一.while 语法 white 条件: 执行代码... 小练习: #打印0-100的偶数 count = 0 while count <= 100: if count %2 == 0 : pr ...

  9. AES-256加密解密

    /// <summary> /// AES-256加密 /// </summary> /// <param name="toEncrypt">& ...

  10. shell脚本—— 字符串操作(长度,查找,替换)

    表达式 含义 ${var} 变量var的值, 与$var相同 ${var-DEFAULT} 如果var没有被声明, 那么就以$DEFAULT作为其值 * ${var:-DEFAULT} 如果var没有 ...