题意 给出一个字符串\(s\)和\(q\)个询问. 每次询问给出两个长度分别为\(k,l\)的序列\(a\)和序列\(b\). 求\(\sum_{i=1}^{k}\sum_{j=1}^{l}lcp(s[a_i-n],s[b_j-n])\) Solution \(SA\)练习题. 求出\(height\)数组后,每次询问相当于询问\(l*k\)个区间\(min\)之和. 岂不单调栈? 对没错,这个题解就是提供给你代码对拍的 #include<bits/stdc++.h> #define For(…
原文链接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)$ 的值. $…
可以用单调栈直接维护出ai所能覆盖到的最大的左右范围是什么,然后我们可以用这个范围暴力的去查询这个区间的是否有满足的点对,一个小坑点,要对左右区间的大小进行判断,只需要去枚举距离i最近的一段区间去枚举即可,复杂度On,如果不判断可以退化成n^2. 10 1 2 3 4 5 6 7 8 9 10 // ——By DD_BOND //#include<bits/stdc++.h> #include<functional> #include<algorithm> #inclu…
构造出的结果一定是一个单峰/\这种样子的 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; pair<]; ],r[];//记录左/右边最近的比当前小的位置 ]; ][];//dp[0][i]表示当a[i]在1~i上单调增时,高度的前缀和,dp[1][i]表示a[i]在i~n单调减时,高度的后缀和(单调可以平,相邻可以相等) int main(){ ios::sync_with_std…
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are…
Codeforces 1107G 线段树最大子段和 + 单调栈 G. Vasya and Maximum Profit Description: Vasya got really tired of these credits (from problem F) and now wants to earn the money himself! He decided to make a contest to gain a profit. Vasya has \(n\) problems to choo…
原文链接http://www.cnblogs.com/zhouzhendong/p/9026184.html 题目传送门 - Codeforces 802I 题意 求一个串中,所有本质不同子串的出现次数的平方和. $|s|\leq 10^5$ 题解 首先,这一题用 SAM 做就是模板题,比较简单. 但是,本着练一练 SA 的心态,我开始了 SA+单调栈 的苦海. 真毒瘤. 这里讲一讲 SA 的做法,也是经典的做法. SA 闭着眼睛先写了再说. 首先,我们考虑出现次数大于 $1$ 次的子串. 考虑…
Mike and Feet Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 548D Appoint description:  Description Mike is the president of country What-The-Fatherland. There are n bears living in thi…
洛谷 Codeforces 我竟然能在有生之年踩标算. 思路 首先考虑暴力:枚举左右端点直接计算. 考虑记录\(sum_x=\sum_{i=1}^x c_i\),设选\([l,r]\)时那个奇怪东西的平方为\(f(l,r)\),使劲推式子: \[ ans_{l,r}=(r-l+1)\times a-sum_r+sum_{l-1}-f(l,r)\\ ans_{l,r}+l\times a-a-sum_{l-1}=r\times a-sum_r-f(l,r)\\ ans_{l,r}+l\times…
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(abs(i-j)<h[i]\),那么向j方向推倒i,j也会倒,问选择任意数量骨牌向任意方向推到,使得全部骨牌都倒下的代价最小 题解 连锁反应可以用单调栈或者链表模拟 定义dp[i]为推倒a[i,m]的最小代价 对于每个i,有两种选择: 向左推:\(dp[l[i]+1]=min(dp[l[i]+1],dp[…