2025.10.12 炼石计划 week7 动规 讲课笔记

记录:1,2 \(\quad\) 3 \(\quad\) 12,8 \(\quad\) 6 \(\quad\) 9 \(\quad\) 10 \(\quad\) 11

题单:

https://www.mxoj.net/training/T1658?groupId=1124&returnUrl=/training/listForGroup?groupId=1124

列表:
- [x] https://www.luogu.com.cn/problem/P11292
- [x] https://qoj.ac/problem/7419
- [x] https://qoj.ac/problem/9489
- [ ] https://www.luogu.com.cn/problem/CF506E
- [x] https://www.luogu.com.cn/problem/P5642
- [x] https://qoj.ac/problem/8047
- [ ] https://www.luogu.com.cn/problem/P9499
- [x] https://qoj.ac/problem/3869
- [x] https://qoj.ac/problem/7606
- [x] https://qoj.ac/problem/6298
- [x] https://www.luogu.com.cn/problem/P5904
- [x] https://www.luogu.com.cn/problem/P7219

T4 CF506E Mr. Kitayuta's Gift

T5 P5642 人造情感(emotion)

\(f_u\) 表示子树 \(u\) 内选择若干不交路径的最大权值和,\(g_u\) 表示子树 \(u\) 外选择若干不交路径的最大权值,则 \(f(u,v)=\sum_{x\notin \text{path}(u,v),fa_x\in\text{path}(u,v)}f_x+g_{\text{lca}(u,v)}\),两者总贡献容易计算(枚举 \(g_u\)\(f_u\) 计算出现次数即可)

考虑如何计算 \(f\)\(g\)

\(s_u=\sum_{v\in\text{son}(u)} f_v\)

将路径保存到端点的 \(\text{lca}\) 上,令 \(S_u=\{(x,y,w)\mid \text{lca}(u,v)=u\}\) 表示对应的路径集合

对于 \(f_u\),若路径不经过 \(u\)\(f_u\gets s_u\),否则枚举它经过 \((x,y,w)\)\(f_u\gets w+\sum_{p\in\text{path}(x,y)}\sum_{q\in\text{son}(p),q\notin\text{path}(x,y)}f_q=w+s_u-\sum_{p\in\text{path}(x,y),p\ne u}(f_p-s_p)\),在 \(\text{dfs}\) 的过程中单点加 \(f_p-s_p\) 链查询,转化为子树加单点查询,用树状树组维护即可(当先计算后加入树状树组时,上部的差分可以省略),同时记录四元组 \((x,y,w,t)\),其中 \(t=w+s_u-\sum_{p\in\text{path}(x,y),p\ne u}(f_p-s_p)\),时间复杂度 \(O((n+m)\log n)\)

对于 \(g_u\),设 \(v\) 为其儿子,从上往下转移,若路径不经过 \(u\)\(g_v\gets g_u+s_u-f_v\),若经过 \((x,y,w,t)\)\(\text{lca}(x,y)=u\)\(v\notin\text{path}(x,y)\),则 \(g_v\gets g_v+w-f_v\),将这部分路径按 \(w\) 从大到小排序,每个 \(v\) 暴力找到第一个满足要求的,显然复杂度正确,若经过 \((x,y,w,t)\)\(\text{lca}(x,y)\ne u,u\in\text{path}(x,y)\)\(v\notin\text{path}(x,y)\),则 \(g_v\gets g_{\text{lca}(x,y)}+t-f_v\)\(\text{dfs}\) 时用一棵线段树维护端点取对应结点时 \(g_{\text{lca}(x,y)}+t\) 的最大值,需要先计算再加入线段树

总时间复杂度 \(O((n+m)\log n)\)

代码

参考

T6 QOJ #8047. DFS Order 4

T7 P9499 「RiOI-2」change

posted @ 2025-10-15 14:11  Hstry  阅读(0)  评论(0)    收藏  举报