忘了当时怎么做的了,先把代码贴上,保存一下后缀数组模板. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define REP(i, a, b) for(int i = a; i < b; i++) #define PER(i, a, b) for(int i = b - 1; i >= a; i--) typedef long long LL;…
原文链接https://www.cnblogs.com/zhouzhendong/p/9256033.html 题目传送门 - CF873F 题意 给定长度为 $n$ 的字符串 $s$,以及给定这个字符串每一个位置是否 “禁止结尾” 的信息. 一个字符串 $a$ 的价值为 $|a|\times f(a)$ . 其中 $f(a)$为 $a$ 在 $s$ 中的匹配次数(如果匹配的结尾为禁止结尾点,那么不算匹配成功) 问在所有的字符串 $a$ 中,$\max(|a|\times f(a)$ 的值. $…
[CF873F]Forbidden Indices 题意:给你一个串s,其中一些位置是危险的.定义一个子串的出现次数为:它的所有出现位置中,不是危险位置的个数.求s的所有子串中,长度*出现次数的最大值. |S|<=200000 题解:板子题啊,沿着pre树统计一下子树权值和,然后用mx*权值和更新答案就好了. #include <cstdio> #include <cstring> #include <iostream> #include <algorith…
刷刷水~ Code: #include <cstdio> #include <cstring> #include <algorithm> #define N 200005 #define setIO(s) freopen(s".in","r",stdin) using namespace std; char str1[N],str2[N]; int tot,last,n,c[N<<1],rk[N<<1];…
题意 给一个长度不超过200000的字符串s,假定有一个字符串a,这个字符串在s中出现次数是f(a),你需要让$|a|f(a)$最大. 但是有一些位置是禁止的,即以该位置为结束位置的字符串不计数. 分析 先不考虑禁止的位置 那么可以求出后缀数组,枚举每一个height[i]作为|a|,向两边扩展,看看其在s中出现了多少次 即找到最宽的[l,r],使得这个区间内最小的数就时height[i] 这只需要两遍单调栈求出每个位置最靠近的小于它的数在哪里就行了 于是该答案就是(r-l+2)*height[…
D. New Year and Ancient Prophecy 题目连接: http://www.codeforces.com/contest/611/problem/C Description Limak is a little polar bear. In the snow he found a scroll with the ancient prophecy. Limak doesn't know any ancient languages and thus is unable to u…
题目链接: https://codeforces.com/contest/432/problem/D 题解: 做法一: KMP 显然next树上\(n\)的所有祖先都是答案,出现次数为next树子树大小. 做法二: 后缀数组/Z-box 按照height分组,二分查找即可. 这种题经常KMP和Z-box都能做. 另外哪位神犇教我一下扩展KMP和Z-box有啥区别. 代码 KMP: #include<cstdio> #include<cstdlib> #include<cstr…
Codeforces 题面传送门 & 洛谷题面传送门 神仙题,做了我整整 2.5h,写篇题解纪念下逝去的中午 后排膜拜 1 年前就独立切掉此题的 ymx,我在 2021 年的第 5270 个小时 A 掉此题,而 ymx 在 2020 年的第 5270 就已经 A 掉了此题 %%%%%% 首先注意到一件事情,就是如果存在一个长度为 \(k\) 的 Journey,那么必然存在一个长度为 \(k\) 的 Journey,满足相邻两个字符串长度的差刚好为 \(1\)(方便起见,在后文中我们及其为 Co…
D. Prefixes and Suffixes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce s…
D. String     You are given a string s. Each pair of numbers l and r that fulfill the condition 1 ≤ l ≤ r ≤ |s|, correspond to a substring of the string s, starting in the position l and ending in the position r (inclusive). Let's define the function…