上一页 1 ··· 29 30 31 32 33 34 35 36 37 ··· 120 下一页
摘要: 和【洛谷5115】挺像的. 都是统计信息的时候是包含两个树的,那就在一个树上边分治,另一个树上跑一个虚树dp就好了. 式子这么拆: $dep[i]+dep[j]-(dep[LCA(i,j)]+dep'[LCA'(i,j)]$ $\Rightarrow dep[i]+dep[j]-\frac{1}{2 阅读全文
posted @ 2019-12-28 14:25 EM-LGH 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 绝对是我写过最长的一份代码了. 这个快敲吐了. 通过这道题能 get 到一个套路: 两颗树同时统计信息的题可以考虑在个树上跑边分治,把点扔到另一颗树的虚树上,然后跑虚树DP. 具体地,这道题中我们发现 $LCP$ 长度是反串后缀树 $LCA$ 深度,$LCS$ 是正串后缀树 $LCA$ 深度. 我们 阅读全文
posted @ 2019-12-27 15:48 EM-LGH 阅读(232) 评论(0) 推荐(0) 编辑
摘要: 这是一道边分治的例题. 一般来说,我们在树上求最优化问题或者求点值固定,但是和边权和有关的问题时可以考虑用一下边分治. 不同与点分治是以点为重心边分,边分治是以边为重心进行分治的. 我们知道,一个点可以和若干条边相连,但是一条边只能连接两个端点,这在统计上就给我们提供了方便(统计两个树的影响就行) 阅读全文
posted @ 2019-12-27 09:03 EM-LGH 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 800年没写DP了,一个傻逼题调半天. code: #include <cstdio> #include <cstring> #include <algorithm> #define N 504 #define inf -10000 #define setIO(s) freopen(s".in"," 阅读全文
posted @ 2019-12-26 20:34 EM-LGH 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 推式子没推出来什么特别有用的结论. 看题解后发现这尼玛就是一个大爆搜啊. 以后碰到这种推式子推不出来,或者没啥思路的时候可以考虑爆搜解决. code: #include <cstdio> #include <string> #include <cstring> #include <algorithm 阅读全文
posted @ 2019-12-26 16:46 EM-LGH 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 这个和 QTREE5 的套路是一样的,就是维护一个深度最深/浅的距离和,然后合并一下就好了. code: #include <map> #include <string> #include <cstdio> #include <cstring> #include <algorithm> #defin 阅读全文
posted @ 2019-12-26 14:57 EM-LGH 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 注意:$LCT$ 在 $link$ 的时候必须要 makeroot. 假如要将 $y$ 连到 $x$ 上: 如果只是将 $y$ Access 并 splay 然后直接连到 $x$ 上的话你会发现 $y$ 在 $splay$ 中所有左儿子其实都在 $(x,y)$ 之间,而这显然就不对了. code: 阅读全文
posted @ 2019-12-26 11:53 EM-LGH 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 对与每一个时刻用主席树维护一下 DFS 序即可. LCA 的话树剖求解比较快. code: #include <cstdio> #include <string> #include <cstring> #include <algorithm> #define N 200006 using names 阅读全文
posted @ 2019-12-26 09:35 EM-LGH 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 大体上的思路不算太难,但是细节巨多无比. 注意我们必须要选一个,所以在记录极差的同时还要记录一下上一次出现的位置. code: #include <cstdio> #include <algorithm> #define setIO(s) freopen(s".in","r",stdin) usin 阅读全文
posted @ 2019-12-25 20:54 EM-LGH 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 这个黑白染色的思路真的是很巧妙啊 code: #include <cstdio> #include <string> #include <algorithm> #define ll long long using namespace std; namespace IO { void setIO(st 阅读全文
posted @ 2019-12-25 20:20 EM-LGH 阅读(285) 评论(0) 推荐(0) 编辑
上一页 1 ··· 29 30 31 32 33 34 35 36 37 ··· 120 下一页