1. 程式人生 > >【Codeforces Round 362 (Div 2)C】【STL-map 最近公共祖先思想】Lorenzo Von Matterhorn 數域二叉樹的路徑權值變更查詢

【Codeforces Round 362 (Div 2)C】【STL-map 最近公共祖先思想】Lorenzo Von Matterhorn 數域二叉樹的路徑權值變更查詢

Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersectionsiand2iand another road betweeniand2i + 1for every positive integeri. You can clearly see that there exists a unique shortest path between any two intersections.

Initially anyone can pass any road for free. But since SlapsGiving is ahead of us, there willqconsecutive events happen soon. There are two types of events:

1. Government makes a new rule. A rule can be denoted by integersv,uandw. As the result of this action, the passing fee of all roads on the shortest path fromu

tovincreases bywdollars.

2. Barney starts moving from some intersectionvand goes to intersectionuwhere there's a girl he wants to cuddle (using his fake name Lorenzo Von Matterhorn). He always uses the shortest path (visiting minimum number of intersections or roads) between two intersections.

Government needs your calculations. For each time Barney goes to cuddle a girl, you need to tell the government how much money he should pay (sum of passing fee of all roads he passes).