SPOJ Substrings】的更多相关文章

传送门 后缀自动机基础题. 求长度为iii的子串出现次数的最大值. 对原串建出samsamsam,然后用sizsizsiz更新每个maxlenmaxlenmaxlen的答案. 然后由于后缀链接将其转化成了一种树形结构,因此直接在上面树形递推即可. 代码 #include<bits/stdc++.h> #define ri register int using namespace std; const int N=5e5+5; int n; char s[N]; struct SAM{ int…
题目链接:戳我 题目大意:给定一个字符串,它的长度n<=2e5.求长度1~n的子串出现的最大次数. 对于一个子串,它的出现次数是多少?就是它所在endpos集合的大小qwq(注意,这里的大小不指该endpos里面元素的个数,而是指该endpos类在原串中出现的次数为大小) 那么我们怎么累加endpos的大小呢qwq 对于一个np节点(非分裂节点),初始的siz值为1,但是分裂节点(nq)就是0了.(指叶子节点) 然后我们在parent tree上用拓扑排序从下到上累加(因为每个节点的parent…
694. Distinct Substrings Problem code: DISUBSTR   Given a string, we need to find the total number of its distinct substrings. Input T- number of test cases. T<=20;Each test case consists of one string, whose length is <= 1000 Output For each test c…
spoj 8222 Substrings 题意:给一个字符串S,令F(x)表示S的所有长度为x的子串中,出现次数的最大值.求F(1)..F(Length(S)) 解题思路:我们构造S的SAM,那么对于一个节点s,它的长度范围是[Min(s),Max(s)],同时他的出现次数是|Right(s)|.那么我们用|Right(s)|去更新F(Max(s))的值.那么现在的问题是如何快速求 |right(s)| 了还记得论文里parent tree吗?看看那个就知道了,不懂可以留言.接下来还有一步,我们…
[SPOJ]Substrings(后缀自动机) 题面 Vjudge 题意:给定一个长度为\(len\)的串,求出长度为1~len的子串中,出现最多的出现了多少次 题解 出现次数很好处理,就是\(right/endpos\)集合的大小 那么,直接构建\(SAM\) 求出每个位置的\(right\)集合大小 直接更新每个节点的\(longest\)就行了 最后短的可以由长的更新过来就好 #include<iostream> #include<cstdio> #include<cs…
[SPOJ]Distinct Substrings(后缀自动机) 题面 Vjudge 题意:求一个串的不同子串的数量 题解 对于这个串构建后缀自动机之后 我们知道每个串出现的次数就是\(right/endpos\)集合的大小 但是实际上我们没有任何必要减去不合法的数量 我们只需要累加每个节点表示的合法子串的数量即可 这个值等于\(longest-shortest+1=longest-parent.longest\) #include<iostream> #include<cstdio&g…
[SPOJ]Distinct Substrings/New Distinct Substrings(后缀数组) 题面 Vjudge1 Vjudge2 题解 要求的是串的不同的子串个数 两道一模一样的题目 其实很容易: 总方案-不合法方案数 对于串进行后缀排序后 不合法方案数=相邻两个串的不合法方案数的和 也就是\(height\)的和 所以\[ans=\frac{n(n+1)}{2}-\sum_{i=1}^{len}height[i]\] #include<iostream> #include…
DISUBSTR - Distinct Substrings no tags  Given a string, we need to find the total number of its distinct substrings. Input T- number of test cases. T<=20; Each test case consists of one string, whose length is <= 1000 Output For each test case outpu…
Distinct Substrings Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on SPOJ. Original ID: DISUBSTR64-bit integer IO format: %lld      Java class name: Main   Given a string, we need to find the total number of its distinct subst…
[SPOJ]Distinct Substrings 求不同子串数量 统计每个点有效的字符串数量(第一次出现的) \(\sum\limits_{now=1}^{nod}now.longest-parents.longest\) My complete code #include<bits/stdc++.h> using namespace std; typedef long long LL; const LL maxn=3000; LL nod,last,n,T; LL len[maxn],fa…