题意翻译 求一个串中包含几个回文串 题目描述 Each palindrome can be always created from the other palindromes, if a single character is also a palindrome. For example, the string "malayalam" can be created by some ways: malayalam = m + ala + y + ala + m malayalam = m…
Number of Palindromes Time Limit: 100MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Submit Status Description Each palindrome can be always created from the other palindromes, if a single character is also a palindrome. For example, the…
SP7586 NUMOFPAL - Number of Palindromes 题意翻译 求一个串中包含几个回文串 输入输出格式 输入格式: The string S. 输出格式: The value of function NumPal(s). 说明 $ 0 < |s| \le 1000$ 简单题,练个手. \(manacher\)求出每个位置回文串长度,把长度加在一起就可以了. Code: #include <cstdio> #include <cstring> cons…
[SPOJ]NUMOFPAL - Number of Palindromes(Manacher,回文树) 题面 洛谷 求一个串中包含几个回文串 题解 Manacher傻逼题 只是用回文树写写而已.. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<…
[CF245H]Queries for Number of Palindromes(回文树) 题面 洛谷 题解 回文树,很类似原来一道后缀自动机的题目 后缀自动机那道题 看到\(n\)的范围很小,但是\(Query\)很多 所以提前预处理出每一段\(l,r\)的答案 时间复杂度\(O(n^2+Q)\) #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #includ…
题意翻译 题目描述 给你一个字符串s由小写字母组成,有q组询问,每组询问给你两个数,l和r,问在字符串区间l到r的字串中,包含多少回文串. 输入格式 第1行,给出s,s的长度小于5000 第2行给出q(1<=q<=10^6) 第2至2+q行 给出每组询问的l和r 输出格式 输出每组询问所问的数量. 题目描述 You've got a string s=\(s_{1}\)\(s_{2}\)...\(s_{|s|}\) of length |s| , consisting of lowercase…
Palindromes and Super Abilities 2 Time Limit: 1MS   Memory Limit: 102400KB   64bit IO Format: %I64d & %I64u Status Description Dima adds letters s1, -, sn one by one to the end of a word. After each letter, he asks Misha to tell him how many new pali…
[Aizu2292]Common Palindromes(回文树) 题面 Vjudge 神TMD日语 翻译: 给定两个字符串\(S,T\),询问\((i,j,k,l)\)这样的四元组个数 满足\(S[i,j],T[k,l]\)都是回文串并且\(S[i,j]=T[k,l]\) 题解 自己\(yy\)一下就会做了 回文树又叫做回文自动机,所以当然可以用来进行回文串的识别和匹配了 对于一个串构建\(PAM\)或者说回文树,统计一下每个回文串的出现次数 再用另外一个串在\(PAM\)上进行匹配,计算一下…
 Palindromes and Super Abilities Problem's Link: http://acm.timus.ru/problem.aspx?space=1&num=1960 Mean: 给你一个长度为n的字符串S,输出S的各个前缀中回文串的数量. analyse: 回文树(回文自动机)的模板题. 由于回文自动机中的p是一个计数器,也相当于一个指针,记录的是当前插入字符C后回文树中有多少个节点. 那么我们只需要一路插,一路输出p-2就行. p-2是因为一开始回文树中就有两个…
A string is palindrome, if the string reads the same backward and forward. For example, strings like "a", "aa", "appa", "queryreuq" are all palindromes. For given empty string S, you should process following two que…
Harry and magic string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 223    Accepted Submission(s): 110 Problem Description Harry got a string T, he wanted to know the number of T's disjoint…
CA loves strings, especially loves the palindrome strings. One day he gets a string, he wants to know how many palindromic substrings in the substring S[l,r] . Attantion, each same palindromic substring can only be counted once. InputFirst line conta…
URAL - 1960   Palindromes and Super Abilities 回文树水题,每次插入时统计数量即可. #include<bits/stdc++.h> using namespace std; #define eps 1e-9 #define For(i,a,b) for(int i=a;i<=b;i++) #define Fore(i,a,b) for(int i=a;i>=b;i--) #define lson l,mid,rt<<1 #d…
19.32% 1000ms 256000K A number is skr, if and only if it's unchanged after being reversed. For example, "12321", "11" and "1" are skr numbers, but "123", "221" are not. FYW has a string of numbers, each su…
Victor and String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/262144 K (Java/Others) Total Submission(s): 163    Accepted Submission(s): 78 Problem Description Victor loves to play with string. He thinks a string is charming as the…
Palindromic Substring Time Limit: 10 Seconds      Memory Limit: 65536 KB In the kingdom of string, people like palindromic strings very much. They like only palindromic strings and dislike all other strings. There is a unified formula to calculate th…
CA Loves Palindromic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 301    Accepted Submission(s): 131 Problem Description CA loves strings, especially loves the palindrome strings. One day…
E. Palisection time limit per test 2 seconds memory limit per test 128 megabytes input standard input output standard output In an English class Nick had nothing to do at all, and remembered about wonderful strings called palindromes. We should remin…
题意翻译 给定一个长度为n的小写字母串.问你有多少对相交的回文子 串(包含也算相交) . 输入格式 第一行是字符串长度n(1<=n<=2*10^6),第二行字符串 输出格式 相交的回文子串个数%51123987 Translated by liyifeng 题目描述 In an English class Nick had nothing to do at all, and remembered about wonderful strings called palindromes. We sh…
回文树(也就是回文自动机)实际上是奇偶两棵树,每一个节点代表一个本质不同的回文子串(一棵树上的串长度全部是奇数,另一棵全部是偶数),原串中每一个本质不同的回文子串都在树上出现一次且仅一次. 一个节点的fail指针指向它的最长回文后缀(不包括自身,所有空fail均连向1).归纳容易证明,当在原串末尾新增一个字符时,回文树上至多会新增一个节点,这也证明了一个串本质不同的回文子串个数不会超过n. 建树时采用增量构造法,当考虑新字符s[i]时,先找到以s[i-1]为结尾的节点p,并不断跳fail.若代表…
题目链接:https://nanti.jisuanke.com/t/41389 The value of a string sss is equal to the number of different letters which appear in this string. Your task is to calculate the total value of all the palindrome substring. Input The input consists of a single…
回文树学习博客:lwfcgz    poursoul 边写边更新,大概会把回文树总结在一个博客里吧... 回文树的功能 假设我们有一个串S,S下标从0开始,则回文树能做到如下几点: 1.求串S前缀0~i内本质不同回文串的个数(两个串长度不同或者长度相同且至少有一个字符不同便是本质不同) 2.求串S内每一个本质不同回文串出现的次数 3.求串S内回文串的个数(其实就是1和2结合起来) 4.求以下标i结尾的回文串的个数 每个变量的含义 1.len[i]表示编号为i的节点表示的回文串的长度(一个节点表示…
Description: 求本质不同回文子串的个数 Solution: 回文树模板,学一学贴一贴啊... Code: /*================================= # Created time: 2016-04-20 20:55 # Filename: hdu3948.cpp # Description: =================================*/ #define me AcrossTheSky&HalfSummer11 #include &l…
The Problem to Slow Down You Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93645#problem/G Description http://7xjob4.com1.z0.glb.clouddn.com/76e435d3c21fa3cbeef1e76780086dc4 Input   Output Sample In…
[CF17E]Palisection(回文树) 题面 洛谷 题解 题意: 求有重叠部分的回文子串对的数量 所谓正难则反 求出所有不重叠的即可 求出以一个位置结束的回文串的数量 和以一个位置为开始的回文串的数量 然后对应的乘一下就行了 求法我用的是回文树 维护每个节点到根节点的距离, 就是回文后缀的数量 CF上的空间是\(128MB\) 卡的很 所以所有的连边考虑用邻接表来代替 #include<iostream> #include<cstdio> #include<cstdl…
[BZOJ2160]拉拉队排练(回文树) 题面 BZOJ 题解 看着题目, 直接构建回文树 求出每个回文串的出现次数 直接按照长度\(sort\)一下就行了 然后快速幂算一下答案就出来了 这题貌似可以用Manacher做吧 求出以每个字符为中心的回文串的最大长度 然后搞一下前缀和就行了 #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cma…
[CF932G]Palindrome Partition(回文树,动态规划) 题面 CF 翻译: 给定一个串,把串分为偶数段 假设分为了\(s1,s2,s3....sk\) 求,满足\(s_1=s_k,s_2=s_{k-1}......\)的方案数 题解 反正我是不会做 基本就是照着\(laofu\)的打了一遍(laofu太强啦) 这题分成了两个步骤 如果直接分\(k\)段我们是没法直接判断的 假设两段\(s_i,s_{k-i+1}\) 因为\(s_i=s_{k-i+1}=x_1x_2.....…
[BZOJ2342]双倍回文(回文树) 题面 BZOJ 题解 构建出回文树之后 在\(fail\)树上进行\(dp\) 如果一个点代表的回文串长度为\(4\)的倍数 并且存在长度为它的一半的回文后缀 那么就是可行的 如何维护长度是一半的回文后缀? \(fail\)树上的父亲一定包括了它的所有的回文后缀 因此在\(fail\)树上\(dfs\),同时记录一下每个长度的回文出现的次数 这样访问到一个节点就可以直接检查了 #include<iostream> #include<cstdio&g…
[BZOJ2565]最长双回文串(回文树) 题面 BZOJ 题解 枚举断点\(i\) 显然的,我们要求的就是以\(i\)结尾的最长回文后缀的长度 再加上以\(i+1\)开头的最长回文前缀的长度 至于最长回文前缀怎么求? 把串反过来前缀不就变成后缀了吗? 所以构造两个回文树就好啦 #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath&g…
回文树/回文自动机 放链接: 回文树或者回文自动机,及相关例题 - F.W.Nietzsche - 博客园 状态数的线性证明 并没有看懂上面的证明,所以自己脑补了一个... 引理: 每一个回文串都是字符串某个前缀的最长回文后缀. 证明. 考虑一个回文串在字符串中第一次出现的位置, 记为 \(S_{p_1 ... p_2}\), 它一定是 \(S_{1 ... p_2}\)的最长回文后缀. 否则, 如果有 \(S_{p_3 ... p_2} (p_3<p_1)\) 也为回文串, 那么由于回文, \…