随笔分类 -  其他 - 思维题

上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 31 下一页
摘要:题意:给定一棵树,每次钦定一个点为根,求以这个点为根时每个点子树权和平方之和,有单点修改. 虽然有修改,但是没有换根操作(等于说每次询问时只换依次根) 我们初始的时候不妨令 $1$ 为根,并考虑当根为 $x$ 时与根为 $1$ 时的差别. 我们发现,当根为 $x$ 时,子树权和发生改变的只是 $1$ 阅读全文
posted @ 2019-12-31 10:06 EM-LGH 阅读(223) 评论(0) 推荐(0)
摘要:就是喜欢后缀自动机,yy了一个只用后缀自动机解决的方法. 对 3 个串建立广义后缀自动机,然后建立后缀树. 标记出每个点在0/1/2个串中是否作为子串出现,然后将后缀树中 2 串结尾的所有子树都设为危险节点. 然后对于 SAM 来一个拓扑序DP,我们开始的时候默认危险节点的最大值是 -inf,然后 阅读全文
posted @ 2019-12-31 08:52 EM-LGH 阅读(187) 评论(0) 推荐(0)
摘要:维护 $\sum_{}v[i]\times dep[i]$ 与 $\sum_{} v[i]\times dep[i]^2$ 其中 $dep[i]$ 表示 $i$ 点在该点所在 $LCT$ 的 $splay$ 中的中序遍历序. 然后正着维护一个,反着维护一个就行了. #include <cstdio> 阅读全文
posted @ 2019-12-30 20:28 EM-LGH 阅读(119) 评论(0) 推荐(0)
摘要:这个期望显然可以表示成总价值/总方案数. 然后我们用线段树依次维护 $\sum val[i]$,$\sum val[i]\times i$,$\sum val[i]\times i^2$ 即可. code: #include <cmath> #include <cstdio> #include <s 阅读全文
posted @ 2019-12-30 15:36 EM-LGH 阅读(169) 评论(0) 推荐(0)
摘要:貌似是套路题. 假设给定我们一些区间,那么这些区间交集的左端点是左端点最靠右区间的左端点. 所以我们将所有区间按照左端点从小到大排序,然后用堆维护前 k 大的右端点. 那么,对于枚举到的第 $i$ 个区间来说,右端点就是第 $k$ 大的右端点与当前区间右端点的较小值. code: #include 阅读全文
posted @ 2019-12-28 16:51 EM-LGH 阅读(123) 评论(0) 推荐(0)
摘要:推一推式子后发现每个点不论走几步被访问到的概率都是 $\frac{d_{i}}{2m}$ code: #include <cstdio> #include <string> #include <algorithm> #define N 100070 #define ll long long #def 阅读全文
posted @ 2019-12-28 16:10 EM-LGH 阅读(134) 评论(0) 推荐(0)
摘要:和【洛谷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 阅读(149) 评论(0) 推荐(0)
摘要:绝对是我写过最长的一份代码了. 这个快敲吐了. 通过这道题能 get 到一个套路: 两颗树同时统计信息的题可以考虑在个树上跑边分治,把点扔到另一颗树的虚树上,然后跑虚树DP. 具体地,这道题中我们发现 $LCP$ 长度是反串后缀树 $LCA$ 深度,$LCS$ 是正串后缀树 $LCA$ 深度. 我们 阅读全文
posted @ 2019-12-27 15:48 EM-LGH 阅读(246) 评论(0) 推荐(0)
摘要:这是一道边分治的例题. 一般来说,我们在树上求最优化问题或者求点值固定,但是和边权和有关的问题时可以考虑用一下边分治. 不同与点分治是以点为重心边分,边分治是以边为重心进行分治的. 我们知道,一个点可以和若干条边相连,但是一条边只能连接两个端点,这在统计上就给我们提供了方便(统计两个树的影响就行) 阅读全文
posted @ 2019-12-27 09:03 EM-LGH 阅读(155) 评论(0) 推荐(0)
摘要:推式子没推出来什么特别有用的结论. 看题解后发现这尼玛就是一个大爆搜啊. 以后碰到这种推式子推不出来,或者没啥思路的时候可以考虑爆搜解决. code: #include <cstdio> #include <string> #include <cstring> #include <algorithm 阅读全文
posted @ 2019-12-26 16:46 EM-LGH 阅读(122) 评论(0) 推荐(0)
摘要:这个和 QTREE5 的套路是一样的,就是维护一个深度最深/浅的距离和,然后合并一下就好了. code: #include <map> #include <string> #include <cstdio> #include <cstring> #include <algorithm> #defin 阅读全文
posted @ 2019-12-26 14:57 EM-LGH 阅读(174) 评论(0) 推荐(0)
摘要:注意:$LCT$ 在 $link$ 的时候必须要 makeroot. 假如要将 $y$ 连到 $x$ 上: 如果只是将 $y$ Access 并 splay 然后直接连到 $x$ 上的话你会发现 $y$ 在 $splay$ 中所有左儿子其实都在 $(x,y)$ 之间,而这显然就不对了. code: 阅读全文
posted @ 2019-12-26 11:53 EM-LGH 阅读(139) 评论(0) 推荐(0)
摘要:大体上的思路不算太难,但是细节巨多无比. 注意我们必须要选一个,所以在记录极差的同时还要记录一下上一次出现的位置. code: #include <cstdio> #include <algorithm> #define setIO(s) freopen(s".in","r",stdin) usin 阅读全文
posted @ 2019-12-25 20:54 EM-LGH 阅读(203) 评论(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 阅读(292) 评论(0) 推荐(0)
摘要:非常有趣的一道题.... code: #include <cstdio> #include <string> #include <algorithm> using namespace std; namespace IO { void setIO(string s) { string in=s+".i 阅读全文
posted @ 2019-12-25 14:59 EM-LGH 阅读(166) 评论(0) 推荐(0)
摘要:code: #include <cstdio> #include <string> #include <algorithm> #define N 500005 #define inf 0.0000000001 using namespace std; namespace IO { void setI 阅读全文
posted @ 2019-12-25 09:35 EM-LGH 阅读(138) 评论(0) 推荐(0)
摘要:这道题的思路很神啊 ~ #include <cstdio> #include <string> #include <cstring> #include <algorithm> using namespace std; const int N=200006; int cur_id; namespace 阅读全文
posted @ 2019-12-24 20:55 EM-LGH 阅读(323) 评论(0) 推荐(0)
摘要:明明可以用二维数点来做啊,网上为什么都是树剖+线段树呢 ? code: #include <cstdio> #include <cstring> #include <algorithm> #define N 100006 #define inf 1000000 #define ll long lon 阅读全文
posted @ 2019-12-24 18:55 EM-LGH 阅读(214) 评论(0) 推荐(0)
摘要:这个题的思路非常好啊. 我们可以把 $k$ 个点拿出来,那么就是求将 $k$ 个点划分成不大于 $m$ 个集合的方案数. 令 $f[i][j]$ 表示将前 $i$ 个点划分到 $j$ 个集合中的方案数. 那么有 $f[i][j]=f[i-1][j-1]+f[i-1][j]*(j-fail[i])$, 阅读全文
posted @ 2019-12-24 13:37 EM-LGH 阅读(146) 评论(0) 推荐(0)
摘要:思路不难,但是细节还是挺多的,要格外注意一下. code: #include <cstdio> #include <queue> #include <cstring> #include <algorithm> #define N 2005 #define ll long long #define m 阅读全文
posted @ 2019-12-23 20:43 EM-LGH 阅读(200) 评论(0) 推荐(0)

上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 31 下一页