Files
hanyixuanten 43d9b98755
Check cpp / md pair / Check md headers (push) Successful in 4s
Sync solutions to Wiki / sync (push) Successful in 4s
fix
2026-10-29 06:04:21 +00:00

17 lines
793 B
Markdown

# P3384 【模板】重链剖分 / 树链剖分 题解
重链剖分模板。习惯用线段树(也可以双 BIT)。
其中:
- [L13-48](../P3384.cpp#L13-L48) 为维护区间和的线段树。
- [L49-59](../P3384.cpp#L49-L59) 为 dfs1,处理 $dep, cnt, fa, son$。
- [L60-71](../P3384.cpp#L60-L71) 为 dfs2,处理 $dfn, top$。
- [L72-80](../P3384.cpp#L72-L80) 为路径加,上跳即可。
- [L81-90](../P3384.cpp#L81-L90) 为路径查询,与修改是类似的。
- [L91-96](../P3384.cpp#L91-L96) 为子树修改与查询,由于子树的 $dfn$ 序列是连续的,直接在线段树上修改即可。
接下来建议用树链剖分解决一些[简单题](https://www.luogu.com.cn/problem/list?type=luogu&page=1&tag=228&orderBy=difficulty&order=asc)。
[code](../P3384.cpp)