Problem
When you learn about Heavy Light Decomposition tree problems take on new meaning. But writing HLD every tree problem with queries so boring. In this post, I will show some problems (as well as ideas for solving them) in which you can write HLD, but with a little thought, the solution becomes easier.
Modifications and receiving at the point
Task: A tree is given, as well as requests to add in a subtree and on the path to the root, as well as to find out the value at the top.
First idea — HLD! But stop, we only need the value at the point, maybe can easier? Yes, we will solve task in offline mode.
Idea: How to find out what changes occurred at the top at time t? Need to store some structure, for example, segment tree and answer for query in time t is sum on prefix t. Now we have add in subtree and on the path to the root. For subtere adding we will remember for each vertex that in its subtree we need to add the number x and the query time.