CF 827E Rusty String FFT】的更多相关文章

传送门 如果没有碍事的?的话,判定字符串的循环节直接用KMP的失配数组就可以搞定.现在有了碍事的?,我们就需要考虑更通用的算法. 考虑KMP失配数组判定字符串循环节的本质,发现判定\(k\)是否为字符串的循环节等价于判定字符串在右移\(k\)位后能否和原字符串匹配(只考虑二者重叠的部分). 我们不妨先把?直接看成一个可以匹配任何字符的通配符,而解决带通配符的字符串匹配问题的一个算法就是FFT. (以下默认下标为\(0\)~\(n-1\)) 设字符串为\(s\),因为字符集只有\(2\),不妨直接…
Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consisted of letters "V" and "K". Unfortunately, rust has eaten some of the letters so that it's now impossible to understand which letter was…
[CF827E]Rusty String 题意:给你一个01串,其中部分字符是'?',?可以是0或1,求所有可能的d,满足存在一种可能得到的01串,在向右移动d格后与自己相同. $n\le 5\times 10^5$ 题解:我们先枚举d,那么一个串符合条件当且仅当:$\forall i \in [0,d), a_i=a_{i+d}=a_{i+2d}=...$,我们可以用fft来判断是否相等.具体地,我们令a串代表正串中的V,b串代表反串中的K,求a和b的卷积c,这样只需要判断$c_d,c_{2d…
E. Rusty String time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standard output Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consisted of letters "V" a…
[题解]Rusty String [CF827E] 传送门:\(\text{Rusty String}\) \(\text{[CF827E]}\) [题目描述] 多组数据,每组数据给出一个由 \(V,K,?\) 三种字符组成的字符串,其中 \(?\) 可以替换为 \(V,K\) 中的任意一个,求替换后的字符串可以存在的循环周期有哪些. [分析] 乍一看像是带通配符的字符串匹配(不会的强烈建议去康康这个),由于字符集不大,按照套路就应该枚举两个字符 \(a \ne b\in\{V,K\}\),然后…
E. String Multiplication 题意 分析: 从后往前考虑字符串变成什么样子. 设$S_i = p_1 \cdot p_2 \dots p_{i}$,最后一定是$S_{n - 1} \cdot p_n$,就是将$S_{n-1}$每两个字符之间放入$p_n$.按照$p_n$分类讨论,那么最后有三种情况. 设$p_n$的开头字符是$c0$,结尾字符是$c1$,包含开头的连续段的长度是$len0$,包含结尾的连续段的长度是$len1$. 1.$c0 \neq c1$,那么答案可以是三…
You are given three integers a, b and x. Your task is to construct a binary string s of length n=a+b such that there are exactly a zeroes, exactly b ones and exactly x indices i (where 1≤i<n) such that si≠si+1. It is guaranteed that the answer always…
题意: 给定一系列字符串,每次都是后一个字符串和前面的融合,这个融合操作就是原来的串分成独立的,然后把新串插入到这些空格中.问最后,最长的相同连续的长度. 思路: 这道题可以贪心的来,我们压缩状态,记录串中每个字母对应最长的长度.然后分类讨论处理就行了. #include <algorithm> #include <iterator> #include <iostream> #include <cstring> #include <cstdlib>…
Description You have a string ss of length nn consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >,…
在校内OJ上A了,没有加强制在线的东西..不放链接了. 这道题题意是维护一个字符串集合,支持三种操作: 1.加字符串 2.删字符串 3.查询集合中的所有字符串在给出的模板串中出现的次数 操作数\(m \le 3*10^5\),输入字符串总长度\(maxL \le 4*10^6\) 对于查询想到了要用AC自动机.但是还要插入和删除,每次插入一个字符串都得重构fail指针,删除更不可做. 对于删除,我们可以新建一颗代表删除的字符串集合的AC自动机,这样查询只要两个AC自动机的值相减即可. 对于插入,…