正文
增加 20 行删除 4 行
14 行未改动151617181920212223242526277 行未改动35363738394041426 行未改动495051525354555657585960616263646566676869707172737413 行未改动88899091929394952 行未改动989910010110210310410510610710810911011111211342 行未改动15615715815916016116216321 行未改动1851861871881891901911922 行未改动19519619719819920020120211 行未改动21421521621714 行未改动- [贪心构造](https://www.luogu.com.cn/article/4igjfcyw)- [通信交互](https://www.luogu.com.cn/article/tny7dxdp)- [数据结构](https://www.luogu.com.cn/article/n2ldeqzn)- [字符串](https://www.luogu.com.cn/article/3sx3vr6y)- [分治](https://www.luogu.com.cn/article/ubh81d1n)- ~~[计数 DP](https://www.luogu.com.cn/article/j5kzbos8)~~- ~~[组合计数](https://www.luogu.com.cn/article/e20z9ju1)~~- [图论](https://www.luogu.com.cn/article/ao0c6mwa)- [背包 DP](https://www.luogu.com.cn/article/1w1occvx)- ~~[树上问题](https://www.luogu.com.cn/article/gtk14ebs)~~- [D](https://www.luogu.com.cn/article/ck6u95z7)[P](https://www.luogu.com.cn/article/56wkso5e)- [Ynoi](https://www.luogu.com.cn/article/209ybs46)7 行未改动- ★ [拆位优化 DP](https://www.luogu.com.cn/article/9bwcvpoe)- ★ [DP 套 DP / DFA 上 DP](https://www.luogu.com.cn/article/8lmx268u)- ★ [延迟钦定贡献 DP](https://www.luogu.com.cn/article/ln32b1sz)- [随机说话 2](https://www.luogu.com.cn/article/kb1xtte9)### ds- ★★ [浅谈网格图分治](https://www.luogu.com.cn/article/9sdqf05s)6 行未改动- ★ [清零警报器](https://www.luogu.com.cn/article/12j8cfca)- ★ [摩尔投票法](https://www.luogu.com.cn/article/kd1o44eh)- ★ [Segment Tree Beats](https://www.luogu.com.cn/article/chkrwjeg)- [双指针](https://www.luogu.com.cn/article/w45lk1jf)- [区间 mex 的刻画手法](https://www.luogu.com.cn/article/osa8l6ex)- ★ [倍增值域分块](https://www.luogu.com.cn/article/dk2qiihz)- ★ [定长分块](https://www.luogu.com.cn/article/tj3g19dt)- ★★ [支配对](https://www.luogu.com.cn/article/8982hs2v)- ★ [换根意义下的子树 DFS 序](https://www.luogu.com.cn/article/e5477znj)- ★ [单侧递归线段树](https://www.luogu.com.cn/article/ts514f2i)- [随机说话 1](https://www.luogu.com.cn/article/3uiou7ex)### graph- ★ [Havel-Hakimi & Erdős-Gallai 定理](https://www.luogu.com.cn/article/szfu472f)- ★ [Redéi 定理 & Camion-Moon 定理](https://www.luogu.com.cn/article/x6sju1ni)- [广义串并联图方法](https://www.luogu.com.cn/article/fbwm6aep)- [广义圆方树](https://www.luogu.com.cn/article/8p89876i)- [双极定向](https://www.luogu.com.cn/article/5c3rl5v1)- ★★★ [最小生成树 / MST](https://www.luogu.com.cn/article/1s6sdmyy)- ★ [连通性问题](https://www.luogu.com.cn/article/if1g72cy)- ★ [SCC 的动态维护](https://www.luogu.com.cn/article/w1o8uly4)### greedy- ★★★ [Shopping Plans Trick](https://www.luogu.com.cn/article/gmgckujq)13 行未改动- [概率论](https://www.luogu.com.cn/article/c6w38wnd)- [斯特林数](https://www.luogu.com.cn/article/ppm1jerq)- ★ [高低位分治](https://www.luogu.com.cn/article/i60ta0hv)- [线性规划对偶](https://www.luogu.com.cn/article/mfyw2qj2)### string- ★★ [字符串无穷幂比较的简单应用](https://www.luogu.com.cn/article/vky4blgo)2 行未改动- ★ [Manacher](https://www.luogu.com.cn/article/rqbyclvv)- ★ [Z 函数 / exKMP](https://www.luogu.com.cn/article/vaqv5bob)- [随机说话 3](https://www.luogu.com.cn/article/p1miuq5x)- ★ [KMP & ACAM](https://www.luogu.com.cn/article/k609ccyh)### tree- [洒水器 & 毛毛虫剖分](https://www.luogu.com.cn/article/pj7re30i)### misc- ★ [排序网络](https://www.luogu.com.cn/article/uw29l2bl)## Tricks### dp42 行未改动- Redéi 定理:任何一个竞赛图都至少存在一条哈密顿路。- Camion-Moon 定理:一个竞赛图存在哈密顿回路,当且仅当它是强连通的。- 网格图格子转边,行列转点建二分图。- E-DCC 必然可以定向为 SCC。因此无向图定向问题考虑缩 E-DCC 变成树上问题。CF555E。### greedy- 01 串邻项操作,对奇 / 偶位取反。21 行未改动### string- bitset 做后缀差分优化字符串匹配。CF914F。- 对 $n$ 个互不相同的模式串 $T_i$,它们在文本串 $S$ 中出现次数之和为 $O\left( |S| \sqrt{\sum \limits_{i=1}^n |T_i|}\right)$。CF963D。### tree- 重心的子树一定能被分为两个集合 $S,T$ 满足 $\max (|S|,|T|) \le \frac{2n}{3}$。P12038、CF1205D、P5811。2 行未改动- 树的度数序列的性质:- $\forall i \in [1,n], d_i \in [1,n)$。- $\sum \limits_{i=1}^n d_i=2n-2$。- 点集 lca 可以转化为 dfs 序最小 / 最大点的两点 lca。CF1062E。### misc- 任意一个单调不降十进制数码都能被表示为至多 $9$ 个形如 $\tt{111\cdots 1}$ 的数的和。P2481。11 行未改动- 对于输出为浮点数的最优化问题,可以设定阈值 $\epsilon$,在当前解 $<\epsilon$ 时剪枝。- 中位数最优化问题,考虑二分答案转为 $\pm 1$ 序列,某段的中位数合法当且仅当段和 $\ge 0$。P17143。- 取模题用 DP 乱搞,数字很大但转移需要取 $\min$ 或 $\max$。考虑维护一个值在 $\log_2$ 意义下的浮点数值,出题人没想卡的话就 win 了。- 写分治卡不过去,考虑小区间暴力算。用这个 2log 卡过了 0.6 秒的 2e6。14 行未改动151617181920212223242526277 行未改动353637383940414243446 行未改动515253545556575859606162636465666768697071727374757677787913 行未改动939495969798991001011021031042 行未改动10710810911011111211311411511611711811912012112212312442 行未改动16716816917017117217317417521 行未改动1971981992002012022032042052 行未改动20820921021121221321421521611 行未改动22822923023123223314 行未改动- [贪心构造](https://www.luogu.com.cn/article/4igjfcyw)- [通信交互](https://www.luogu.com.cn/article/tny7dxdp)- [数据结构](https://www.luogu.com.cn/article/n2ldeqzn)- [图论](https://www.luogu.com.cn/article/ao0c6mwa)- [字符串](https://www.luogu.com.cn/article/3sx3vr6y)- [分治](https://www.luogu.com.cn/article/ubh81d1n)- ~~[计数 DP](https://www.luogu.com.cn/article/j5kzbos8)~~- ~~[组合计数](https://www.luogu.com.cn/article/e20z9ju1)~~- [背包 DP](https://www.luogu.com.cn/article/1w1occvx)- ~~[树上问题](https://www.luogu.com.cn/article/gtk14ebs)~~- [D](https://www.luogu.com.cn/article/ck6u95z7)[P](https://www.luogu.com.cn/article/56wkso5e)- [Ynoi](https://www.luogu.com.cn/article/209ybs46)7 行未改动- ★ [拆位优化 DP](https://www.luogu.com.cn/article/9bwcvpoe)- ★ [DP 套 DP / DFA 上 DP](https://www.luogu.com.cn/article/8lmx268u)- ★ [延迟钦定贡献 DP](https://www.luogu.com.cn/article/ln32b1sz)- [随机说话 2](https://www.luogu.com.cn/article/kb1xtte9)- ★ [换根 DP](https://www.luogu.com.cn/article/tpekict3)- [树上依赖性背包](https://www.cnblogs.com/stripe-python/p/23644262)### ds- ★★ [浅谈网格图分治](https://www.luogu.com.cn/article/9sdqf05s)6 行未改动- ★ [清零警报器](https://www.luogu.com.cn/article/12j8cfca)- ★ [摩尔投票法](https://www.luogu.com.cn/article/kd1o44eh)- ★ [Segment Tree Beats](https://www.luogu.com.cn/article/chkrwjeg)- [双指针](https://www.luogu.com.cn/article/w45lk1jf)- ★ [区间 mex 的刻画手法](https://www.luogu.com.cn/article/gu0a95ay)- ★ [倍增值域分块](https://www.luogu.com.cn/article/dk2qiihz)- ★ [定长分块](https://www.luogu.com.cn/article/tj3g19dt)- ★★ [支配对](https://www.luogu.com.cn/article/8982hs2v)- ★ [换根意义下的子树 DFS 序](https://www.luogu.com.cn/article/e5477znj)- ★ [单侧递归线段树](https://www.luogu.com.cn/article/ts514f2i)- [随机说话 1](https://www.luogu.com.cn/article/3uiou7ex)- [李超线段树](https://www.luogu.com.cn/article/y9l1btm4)- ★ [缺一分治](https://www.luogu.com.cn/article/lzlc8lin)### graph- ★ [Havel-Hakimi & Erdős-Gallai 定理](https://www.luogu.com.cn/article/szfu472f)- ★★ [竞赛图相关](https://www.luogu.com.cn/article/x6sju1ni)- [广义串并联图方法](https://www.luogu.com.cn/article/fbwm6aep)- [广义圆方树](https://www.luogu.com.cn/article/8p89876i)- [双极定向](https://www.luogu.com.cn/article/5c3rl5v1)- ★★★ [最小生成树 / MST](https://www.luogu.com.cn/article/1s6sdmyy)- ★ [连通性问题](https://www.luogu.com.cn/article/if1g72cy)- [SCC 的动态维护](https://www.luogu.com.cn/article/w1o8uly4)- [最小 Steiner 树学习笔记](https://www.luogu.com.cn/article/wrmzxmn4)### greedy- ★★★ [Shopping Plans Trick](https://www.luogu.com.cn/article/gmgckujq)13 行未改动- [概率论](https://www.luogu.com.cn/article/c6w38wnd)- [斯特林数](https://www.luogu.com.cn/article/ppm1jerq)- ★ [高低位分治](https://www.luogu.com.cn/article/i60ta0hv)- [线性规划对偶](https://www.luogu.com.cn/article/mfyw2qj2)- [动态 FMT](https://www.luogu.com.cn/article/5u98v08y)- ★ [Newton 恒等式](https://www.luogu.com.cn/article/abi0qcep)- [格路计数](https://www.luogu.com.cn/article/cs859p7x)- [$O(n^2)$ 多项式初等函数](https://www.cnblogs.com/stripe-python/p/23525601)### string- ★★ [字符串无穷幂比较的简单应用](https://www.luogu.com.cn/article/vky4blgo)2 行未改动- ★ [Manacher](https://www.luogu.com.cn/article/rqbyclvv)- ★ [Z 函数 / exKMP](https://www.luogu.com.cn/article/vaqv5bob)- [随机说话 3](https://www.luogu.com.cn/article/p1miuq5x)- ★ [KMP & ACAM](https://www.luogu.com.cn/article/k609ccyh)- ★ [矩阵乘法 Hash](https://www.cnblogs.com/stripe-python/p/23569614)### tree- [洒水器 & 毛毛虫剖分](https://www.luogu.com.cn/article/pj7re30i)### misc- ★ [排序网络](https://www.luogu.com.cn/article/uw29l2bl)- ★★ [冒泡排序相关结论](https://www.cnblogs.com/stripe-python/p/23657566)## Tricks### dp42 行未改动- Redéi 定理:任何一个竞赛图都至少存在一条哈密顿路。- Camion-Moon 定理:一个竞赛图存在哈密顿回路,当且仅当它是强连通的。- 网格图格子转边,行列转点建二分图。- E-DCC 必然可以定向为 SCC。因此无向图定向问题考虑缩 E-DCC 变成树上问题。CF555E。- 已知若干区间和,凑出给定区间和的问题,考虑图论建模。取前缀和 $s_i$,已知 $s_r-s_{l-1}$ 连边 $l-1 \leftrightarrow r$。询问 $(l,r)$ 就是 $l-1 \leadsto r$ 的图上路径,正向经过就加,反向经过就减。ABC355E、P10145。### greedy- 01 串邻项操作,对奇 / 偶位取反。21 行未改动### string- bitset 做后缀差分优化字符串匹配。CF914F。- 对 $n$ 个互不相同的模式串 $T_i$,它们在文本串 $S$ 中出现次数之和为 $O\left( |S| \sqrt{\sum \limits_{i=1}^n |T_i|}\right)$。CF963D。- 将原串按照 $s_1s_ns_2s_{n-1}\cdots$ 的顺序重排,border 转化为回文前缀:$ABA \to AA^R B$。P3546、P14830。### tree- 重心的子树一定能被分为两个集合 $S,T$ 满足 $\max (|S|,|T|) \le \frac{2n}{3}$。P12038、CF1205D、P5811。2 行未改动- 树的度数序列的性质:- $\forall i \in [1,n], d_i \in [1,n)$。- $\sum \limits_{i=1}^n d_i=2n-2$。- 点集 lca 可以转化为 dfs 序最小 / 最大点的两点 lca。CF1062E。- 点分治维护信息状物,可以时光倒流以后并查集维护连通块。QOJ12180、P9352。### misc- 任意一个单调不降十进制数码都能被表示为至多 $9$ 个形如 $\tt{111\cdots 1}$ 的数的和。P2481。11 行未改动- 对于输出为浮点数的最优化问题,可以设定阈值 $\epsilon$,在当前解 $<\epsilon$ 时剪枝。- 中位数最优化问题,考虑二分答案转为 $\pm 1$ 序列,某段的中位数合法当且仅当段和 $\ge 0$。P17143。- 取模题用 DP 乱搞,数字很大但转移需要取 $\min$ 或 $\max$。考虑维护一个值在 $\log_2$ 意义下的浮点数值,出题人没想卡的话就 win 了。- 写分治卡不过去,考虑小区间暴力算。用这个 2log 卡过了 0.6 秒的 2e6。- 对于一类可以扩展的最优化问题,每次扩展时将上界 / 下界设为当前答案再开始枚举,复杂度可以均摊。P12202、CF1967D。- 序列 $b_1 \sim b_m$ 可单栈排序,当且仅当 $\nexists 1 \le i<j<k \le m,a_k<a_i<a_j$。ABC262G。