Data Structures19 sections · 729 units
Open in Course

Challenge: Combined Techniques

Putting it together

Here's a challenge to test your understanding: Given a tree, support these operations:

1.1. Add vv to all nodes on path from uu to ww

2.2. Query sum of values in subtree of uu

This requires combining HLD (for path updates) with Euler tour (for subtree queries). Here's the trick: use HLD to handle path updates, but store values in Euler tour order so subtree queries are ranges. Think about how the data structures interact before looking up solutions. Build: O(n)O(n). Path update: O(log2n)O(\log^2 n). Subtree query: O(logn)O(\log n). Space: O(n)O(n).