I came across this question in a contest (which is now over) and I am not able to think of a time-efficient algorithm.
You are given a rooted Tree of N ( <=10^5) nodes . Initially all nodes have value 0.There would be M updates (<=10^5) to the tree which are of the form
Add x y – Add y to node x .
AddUp x y – Add y to x , parent of x , parent of parent of x uptill Root.
After that there will be Q queries ( <=10^5) queries where you will either be asked to give the value of a node or the sum of subtree rooted at that node.
What I did:-
First I tried the naive algorithm that would update each node according to the operation, but obviously it is time taking.
I also thought of using segment trees and Lazy propogation but cannot think of a proper way.
Any help is appreciated , Thanks!