大意: 求重复$k$次的子串个数 枚举重复长度$i$, 把整个串分为$n/i$块, 如果每块可以$O(1)$计算, 那么最终复杂度就为$O(nlogn)$ 有个结论是: 以$j$开头的子串重复次数最大为$1+\lfloor\frac{lcp(j,j+i)}{i}\rfloor$ 先特判掉$k=1$的情况, 然后枚举每个块开头的位置, 计算出$lcp$的值$p$, 由于$k>1$, 合法位置的$lcp$值至少要跨越一个块, 可以得到 若$p\ge ki-1$, 那么这个块内所有点都合法 若$k(i…
Acesrc and String Theory Problem Description Acesrc is a famous string theorist at Nanjing University second to none. He insists that we should always say an important thing k times. He also believes that every string that can be obtained by concaten…
string string string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 608    Accepted Submission(s): 167 Problem Description Uncle Mao is a wonderful ACMER. One day he met an easy problem, but U…
Rabbit's String Problem Description Long long ago, there lived a lot of rabbits in the forest. One day, the king of the rabbit kingdom got a mysterious string and he wanted to study this string. At first, he would divide this string into no more than…
hdu题目 poj题目 参考了 罗穗骞的论文<后缀数组——处理字符串的有力工具> 题意:求两个序列的最长公共子串 思路:后缀数组经典题目之一(模版题) //后缀数组sa:将s的n个后缀从小到大排序后将 排序后的后缀的开头位置 顺次放入sa中,则sa[i]储存的是排第i大的后缀的开头位置.简单的记忆就是“排第几的是谁”. //名次数组rank:rank[i]保存的是suffix(i){后缀}在所有后缀中从小到大排列的名次.则 若 sa[i]=j,则 rank[j]=i.简单的记忆就是“你排第几”…
题意:给定一个长度为n(n<=150000)的字符串,每个下标i与(i*i+1)%n连边,求从任意下标出发走n步能走出的字典序最大的字符串. 把下标看成结点,由于每个结点有唯一的后继,因此形成的是外向基环树森林,相当于求基环树上字典序最大的路径. 实际上基环树和树一样是可以通过倍增得到走2^k步能走到的结点的,然后后缀数组又可以通过倍增求出长度为2^k的后缀的字典序,两者结合一下就可以对所有路径按字典序排序了. 复杂度$O(nlogn)$,感觉这应该是标解吧,不过由于数据可能比较随机因此直接BF…
Problem Description In this problem, you are given a string s and q queries. For each query, you should answer that when all distinct substrings of string s were sorted lexicographically, which one is the k-th smallest.  A substring si...j of the str…
题目链接 思路 想到了,但是木写对啊....代码 各种bug,写的乱死了.... 输出最靠前的,比较折腾... #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <cmath> #include <map> using namespace std; #define N 501000 #define LL __in…
Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 14096    Accepted Submission(s): 6462 Problem Description It is well known that AekdyCoin is good at string problems as well as…
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description It is well known that AekdyCoin is good at string problems as well as number theory problems. When given a string s, we can write do…
练习一下字符串,做一下这道题. 首先是关于一个字符串有多少不同子串的问题,串由小到大排起序来应该是按照sa[i]的顺序排出来的产生的. 好像abbacd,排序出来的后缀是这样的 1---abbacd     第一个串产生的6个前缀都是新的子串 2---acd          第二个串除了和上一个串的前缀1 3-1=2 产生了2个子串 3---bacd        4-0=4 4---bbacd      5-1=4 5---cd           2-0=0 6---d          …
题意:统计前缀在串中出现的次数 思路:next数组,递推 #include<iostream> #include<stdio.h> #include<string.h> using namespace std; #define MaxSize 200005 #define Mod 10007 char str[MaxSize]; int _next[MaxSize]; int dp[MaxSize]; int len; void GetNext(char t[]){//…
题意 在 \(S\) 中找出 \(t\) 个子串满足 \(t_{i+1}\) 是 \(t_{i}\) 的子串,要让 \(t\) 最大. \(|S| \leq 5\times 10^5\). 分析 定义状态 \(f_{i}\) 表示从 \(i\) 出发能够得到的最长的 \(journey\) . 容易得到最终的答案最右边的串长度一定可以是1. 同时如果删掉没用的部分过后 \(t_i\) 的长度一定可以为 $t_{i+1} +1 $. 如果在 \(i\) 位置存在长度为 \(k\) 的答案的话,将两…
题意 大概就是给你一个串,对于每个\(i\),在\([1,i-1]\)中找到一个\(j\),使得\(lcp(i,j)\)最长,若有多个最大\(j\)选最小,求\(j\)和这个\(lcp\)长度 思路 首先我们需要知道对于每个\(i\),能与下标小于\(i\)开头的前缀构成的最大\(lcp\)是多少 这个可以在最外层枚举\(i\)的过程中维护一个\(set\),这样在插入当前的\(rk[i]\)的时候能\(O(logn)\)得到这个最长的\(lcp\) 然后根据这个值二分出\(rk[i]\)向左右…
hdu 3553 Just a String (后缀数组) 题意:很简单,问一个字符串的第k大的子串是谁. 解题思路:后缀数组.先预处理一遍,把能算的都算出来.将后缀按sa排序,假如我们知道答案在那个区间范围内了(假设为[l,r]),那么我们算下这个区间内的lcp的最小值(设最小值的位置为mid,大小为x),如果x*(r-l+1)>=k,那么,答案就是这个区间的lcp的最小值的某一部分(具体是哪一部分,画个图稍微算下就出来了).如果x * ( r - l + 1 ) < k 那么我们分两种情况…
题目链接 Problem Description Uncle Mao is a wonderful ACMER. One day he met an easy problem, but Uncle Mao was so lazy that he left the problem to you. I hope you can give him a solution.Given a string s, we define a substring that happens exactly k time…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6194 题意:告诉你一个字符串和k , 求这个字符串中有多少不同的子串恰好出现了k 次. 解法:后缀数组.我们先考虑至少出现k 次的子串, 所以我们枚举排好序的后缀i (sa[i]) .然后k段k 段的枚举.假设当前枚举的是 sa[i]~sa[i + k -1],那么假设这一段的最长公共前缀  是L 的话.那么就有L 个不同的子串至少出现了k次.我们要减去至少出现k + 1次的 , 但还要和这个k 段…
题意:给定一个字符串,问你它有多少个子串恰好出现 k 次. 析:后缀数组,先把height 数组处理出来,然后每次取 k 个进行分析,假设取的是 i ~ i+k-1,那么就有重复的,一个是 i-1 ~ i+k-1,另一个是 i ~ i+k,但是这样就删多了,再加上 i - 1 ~ i+k,这样就OK了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #inclu…
转自:http://blog.csdn.net/aozil_yang/article/details/77929216 题意: 告诉你一个字符串和k , 求这个字符串中有多少不同的子串恰好出现了k 次. 思路: 后缀数组. 我们先考虑至少出现k 次的子串, 所以我们枚举排好序的后缀i (sa[i]) . k段k 段的枚举. 假设当前枚举的是 sa[i]~sa[i + k -1] 那么假设这一段的最长公共前缀  是L 的话. 那么就有L 个不同的子串至少出现了k次. 我们要减去至少出现k + 1次…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5558 Problem Description Alice wants to send a classified message to Bob. She tries to encrypt the message with her original encryption method. The message is a string S, which consists of Nlowercase let…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3948 题意:给定一个字符串,求字符串本质不同的回文子串个数. 思路:主要参考该篇解题报告 先按照manacher的构造方法改造一遍串,然后跑一遍manacher.求出以i为中心的最长回文串长度p[i]. 然后跑一遍后缀数组,若已经求得后缀sa[i-1]对答案的贡献,然后现在计算后缀sa[i],本来是要加上以sa[i]为中心的回文串的个数p[sa[i]]. 我们可以维护一个tmp,也就是上图中蓝色的框…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5769 [2016多校contest-4] 题意:给定一个字符,还有一个字符串,问这个字符串存在多少个不同的子串并且子串含有给定的字符. 思路:先忽略包含某个字符的问题,只求一个字符串不同的子串个数,根据<<后缀数组——处理字符串的有力工具>>,每个子串一定是某个后缀的前缀, 那么一个字符串不同的子串个数等价于求所有后缀之问的不相同的前缀的个数 .如果所有的后缀按照 suffix(sa[…
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5008 Description In this problem, you are given a string s and q queries. For each query, you should answer that when all distinct substrings of string s were sorted lexicographically, which one is…
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5853 Description Jong Hyok loves strings. One day he gives a problem to his friend you. He writes down n strings Pi in front of you, and asks m questions. For i-th question, there is a string Qi. We…
Boring counting Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=3518 Mean: 给你一个字符串,求:至少出现了两次(无重叠)的子串的种类数. analyse: 后缀数组中height数组的运用,一般这个数组用得很少. 总体思路:分组统计的思想:将相同前缀的后缀分在一个组,然后对于1到len/2的每一个固定长度进行统计ans. 首先我们先求一遍后缀数组,并把height数组求出来.height数组代表的含…
Favorite Donut Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5442 Description Lulu has a sweet tooth. Her favorite food is ring donut. Everyday she buys a ring donut from the same bakery. A ring donut is consis…
http://acm.hdu.edu.cn/showproblem.php?pid=1403 Longest Common Substring Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3068    Accepted Submission(s): 1087 Problem Description Given two string…
hdu 4622 Reincarnation 题意:还是比较容易理解,给出一个字符串,最长2000,q个询问,每次询问[l,r]区间内有多少个不同的字串. (为了与论文解释统一,这里解题思路里sa数组的值是从1到n,但其实代码中我的sa数组的值是从0到n-1). 解题思路:09年的后缀数组论文里有一个类似的题,求一个字串的不同字串有多少个.问不同的字串有多少个,即问对于每一个后缀,它的所有前缀中,与其他后缀的前缀不同的有几个.解法是按rank从大到小将后缀一个个加进来,那么每加进一个后缀,将会增…
hdu 4691 Front compression 题意:很简单的,就是给一个字符串,然后给出n个区间,输出两个ans,一个是所有区间的长度和,另一个是区间i跟区间i-1的最长公共前缀的长度的数值的长度,加上不是公共部分的字符个数,加2,累加起来. 解题思路:后缀数组裸题..用rmq求最长公共前缀,询问就是o(1)的.有队伍用暴力的方法过的,对于i区间与i-1区间,如果左端点一样,就去长度小的那个,否则就暴力枚举相同的前缀.但我认为这样是不可以的,比如我的数据是10w个a,询问10w,第i个区…
The Number of Palindromes Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 2465    Accepted Submission(s): 841 Problem Description Now, you are given a string S. We want to know how many distin…