CF 149E Martian Strings 后缀自动机】的更多相关文章

这里给出来一个后缀自动机的题解. 考虑对 $s$ 的正串和反串分别建后缀自动机. 对于正串的每个节点维护 $endpos$ 的最小值. 对于反串的每个节点维护 $endpos$ 的最大值. 这两个东西通过一个简单的基数排序就可以实现. 将 $p$ 的正串在正串的 SAM 上去匹配,一直匹配到匹配不了为止,并记录 $p[i]$ 在正串中自动机节点上 $endpos$ 的最小值 $a[i]$. 对 $p$ 的反串也进行相同的处理,记录 $endpos$ 的最大值 $b[i]$. 正串中的 $endp…
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…
上学期很认真地学了一些字符串的常用工具,各种 suffix structre,但是其实对后缀自动机这个部分是理解地不太透彻的,以致于看了师兄A这题的代码后,我完全看不懂,于是乎重新看回一些学习后缀自动机的博客和代码,重新理解了一些概念,感觉自己对于后缀自动机的理解深了一些. 先说说题意,给了三个串,问对于长度为x的串,满足(i1,i2,i3)(s1[i1..i1+k-1]==s2[i2...i2+k-1]==s3[i3+i3+k-1])有多少组,要输出全部的组数. 师兄的代码的做法是这样的,插入…
Martian Strings 题解: 对于询问串, 我们可以从前往后先跑一遍exkmp. 然后在倒过来,从后往前跑一遍exkmp. 我们就可以记录下 对于每个正向匹配来说,最左边的点在哪里. 对于每个反向匹配来说,最右边的点在哪里. 然后判断可不可以构成这个串就好了. 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin);…
题意:给一个主串和多个询问串,求询问串的所有样子不同的周期同构出现次数和 没有周期同构很简单就是询问串出现次数,|Right| 有了周期同构,就是所有循环,把询问串复制一遍贴到后面啊!思想和POJ1509相似,不要局限于复制主串 然后走的时候维护nowLen 需要支持尾部插入字符(走转移边)和首部删除字符(走parent边)就行了 PS:家里上CF太慢了还是学校网速快 #include <iostream> #include <cstdio> #include <algori…
传送门 解题思路 感觉这种题都是套路之类的??首先把三个串并成一个,中间插入一些奇怪的字符,然后跑遍\(SA\).考虑按照\(height\)分组计算,就是每个\(height\)只在最高位计算一次,然后求个后缀和,这个可以并查集来实现.具体就是记一个\(sum[i][3]\)表示第\(i\)个联通块中\(0,1,2\)的个数,\(0,1,2\)就是出现在三个串的哪一个,然后合并时需要容斥一下. 代码 #include<iostream> #include<cstdio> #inc…
题目链接 给一个字符串s, n个字符串str. 令tmp为s中不重叠的两个连续子串合起来的结果, 顺序不能改变.问tmp能形成n个字符串中的几个. 初始将一个数组dp赋值为-1. 对str做kmp, 然后与串s进行匹配, 看哪些长度的串可以匹配到, 比如说匹配到了长度为j的串, 那么dp[j] = i, i是此时串s的位置. 然后将s和str都反转, 在做一次kmp, 在进行匹配, 对于匹配到的长度j, 看dp[lenStr-j]是否为-1, 如果不为-1, 看lenS-i是否大于等于dp[le…
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…
You are given n strings ti. Each string has cost ci. Let's define the function of string , where ps, i is the number of occurrences of s in ti, |s| is the length of the string s. Find the maximal value of function f(s) over all strings. Note that the…