上学期很认真地学了一些字符串的常用工具,各种 suffix structre,但是其实对后缀自动机这个部分是理解地不太透彻的,以致于看了师兄A这题的代码后,我完全看不懂,于是乎重新看回一些学习后缀自动机的博客和代码,重新理解了一些概念,感觉自己对于后缀自动机的理解深了一些. 先说说题意,给了三个串,问对于长度为x的串,满足(i1,i2,i3)(s1[i1..i1+k-1]==s2[i2...i2+k-1]==s3[i3+i3+k-1])有多少组,要输出全部的组数. 师兄的代码的做法是这样的,插入…
Some days ago, WJMZBMR learned how to answer the query "how many times does a string x occur in a string s" quickly by preprocessing the string s. But now he wants to make it harder. So he wants to ask "how many consecutive substrings of s…
The Dominator of Strings Time Limit: 3000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Problem Description Here you have a set of strings. A dominator is a string of the set dominating all strings else. The string S is dominated…
用后缀自动机统计出出现1~n次的串的数量f[i] 对于ans[k]=sigma(f[i]*C(i,k)) i>=k ; mo=; ..maxn] of dword; nt:..maxn,'a'..'z'] of longint; last,sum,i:dword; s:ansistring; eg:..maxn*] of record nt,v:dword; end; lt:..maxn] of dword; el:dword; time:..maxn] of qword; T,j,TT:dwo…
原文链接https://www.cnblogs.com/zhouzhendong/p/CF542E.html 题目传送门 - CF452E 题意 给定三个字符串 $s1,s2,s3$ ,对于所有 $L\in{1,2,\cdots,min(|s1|,|s2|,|s3|)}$ ,输出 $f(L)$ . 其中 $f(L)$ 表示满足 $s_k[i_k,\cdots,i_k+L-1]$ 全部相同的 $i_1,i_2,i_3$ 的个数. 答案对 $10^9+7$ 取模. $|s1|+|s2|+|s3|\l…
这里给出来一个后缀自动机的题解. 考虑对 $s$ 的正串和反串分别建后缀自动机. 对于正串的每个节点维护 $endpos$ 的最小值. 对于反串的每个节点维护 $endpos$ 的最大值. 这两个东西通过一个简单的基数排序就可以实现. 将 $p$ 的正串在正串的 SAM 上去匹配,一直匹配到匹配不了为止,并记录 $p[i]$ 在正串中自动机节点上 $endpos$ 的最小值 $a[i]$. 对 $p$ 的反串也进行相同的处理,记录 $endpos$ 的最大值 $b[i]$. 正串中的 $endp…
[题目链接] https://codeforces.com/contest/452/problem/E [算法] 构建后缀数组 用并查集合并答案即可 时间复杂度 : O(NlogN) [代码] #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; ; ; #define rint register int…
传送门 解题思路 感觉这种题都是套路之类的??首先把三个串并成一个,中间插入一些奇怪的字符,然后跑遍\(SA\).考虑按照\(height\)分组计算,就是每个\(height\)只在最高位计算一次,然后求个后缀和,这个可以并查集来实现.具体就是记一个\(sum[i][3]\)表示第\(i\)个联通块中\(0,1,2\)的个数,\(0,1,2\)就是出现在三个串的哪一个,然后合并时需要容斥一下. 代码 #include<iostream> #include<cstdio> #inc…
题目链接 \(Description\) 给定一个字符串\(s[1]\).一个字符串序列\(s[\ ]\)满足\(s[i]\)至少在\(s[i-1]\)中出现过两次(\(i\geq 2\)).求最大的\(k\),满足存在\(s[1]\sim s[k]\). \(|s[1]|\leq2\times10^5\). \(Solution\) 一开始以为直接自底向上合并right,如果|right|>1就继续向上.这显然不对啊,这样出现次数>1不一定是在之前的子节点中出现次数>1. 如果串\(A…
E. Little Elephant and Strings time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output The Little Elephant loves strings very much. He has an array a from n strings, consisting of lowercase Englis…