Company: De Shaw Testing role(sdet)
Difficulty: medium
Update Nodes at K Distance A binary tree holds N nodes numbered 1 through N in heap order: node 1 is the root, and for any node i the node numbered 2i is its left child and the node numbered 2i+1 is its right child, whenever those numbers are at most N. Nodes whose child indices exceed N simply have fewer children. The distance between two nodes is the number of edges on the unique path joining them, and a path may travel up to a parent and back down into another subtree. Every node starts holding the value 0. You are then given Q update operations, applied in the order they are listed. An operation is written as three integers u k v and it adds v to the value of every node whose distance from node u is exactly k . Node u is at distance 0 from itself. After all Q operations have been applied, report the value held by every node. Input Format The first line contains two integers N and Q . Each of the next Q lines contains three integers u , k and v describing one operation. Output Forma