Irrigation Lazy Tree Problem
Irrigation Lazy Tree Problem — ExecCode Hard DSA Practice
Solve the Irrigation Lazy Tree problem on ExecCode. Free online hard DSA practice in Graph. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Pipes form a tree rooted at 0. Opening a valve at a junction adds delta liters to every descendant, including itself. Inspectors later ask how much water a single junction currently holds. An Euler tour turns a subtree into a contiguous range, then a lazy segment tree range-adds and point-queries. Start with zeros. Type 0 u d adds d to the subtree of u. Type 1 u appends the value at u. Return the appended values. Nodes begin at 0. You are given: n — junctions edges — tree edges queries — operations Return values from type-1 queries. Adds stack: two subtree adds that both cover u both affect the later point query.
Examples
Input {'n': 4, 'edges': [[0, 1], [0, 2], [2, 3]], 'queries': [[0, 2, 5], [1, 3], [1, 0], [0, 0, 1], [1, 3]]}; Output [5, 0, 6]. Input {'n': 1, 'edges': [], 'queries': [[0, 0, 4], [1, 0]]}; Output [4]. Input {'n': 3, 'edges': [[0, 1], [1, 2]], 'queries': [[0, 1, 2], [1, 0], [1, 2]]}; Output [0, 2]
Constraints
Root 0 d may be negative
Practice Irrigation Lazy Tree free on ExecCode. Browse DSA problems, topic map, and placement guides.