--- id: hld title: "Heavy-Light Decomposition" author: Benjamin Qi prerequisites: - Gold - Euler Tour Technique - Platinum - Range Update Range Query description: Path and subtree updates and queries. frequency: 1 --- import { Problem } from "../models"; export const metadata = { problems: { sample: [ new Problem("CSES", "Company Queries II", "1688", "Intro|Easy", false, ["LCA"], "Pure implementation; see Benq's library code, it has a function for LCA. Though this problem can be solved with binary lifting as well, you should do it with HLD to get practice."), ], general: [ new Problem("Gold", "Milk Visits", "970", "Easy", false, ["HLD"], "This has a linear time solution, but it's easier to make modifications to the HLD template."), new Problem("Gold", "Cow Land", "921", "Easy", false, ["PURS", "HLD"], ""), new Problem("Old Gold", "Grass Planting", "102", "Intro|Easy", false, ["HLD", "PURS"], ""), new Problem("Plat", "Disrupt", "842", "Easy", false, ["HLD"], ""), new Problem("HR", "Subtrees & Paths", "https://www.hackerrank.com/challenges/subtrees-and-paths", "Intro|Easy", false, ["HLD", "RURQ"], "See adamant's blog."), new Problem("YS","Vertex Set Path Composite","vertex_set_path_composite", "Intro|Normal", false, ["HLD", "SegTree"], "Function order matters! Maintain two segment trees, one for going up and the other for going down the tree."), new Problem("CF", "Tree Queries", "contest/1254/problem/D", "Hard", false, ["HLD"], "maybe hard to see why this applies here, gives $O(N\\log N)$ while most people solved it with some factor of $\\sqrt N$"), new Problem("ojuz", "JOI - Synchronization", "JOI13_synchronization", "Hard", false, ["HLD"], "$O(N\\log N)$ :D"), new Problem("ojuz", "JOI - Cats or Dogs", "JOI18_catdog", "Very Hard", false, ["HLD"], ""), ], } }; ## Tutorial For an alternate implementation, see below explains what HLD is (but incomplete & overly complicated code) ## Implementations not complete complete implementation following the above two articles with minor modifications ## Problems