CF696A.Lorenzo Von Matterhorn

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections ii and 2i2i and another road between ii and 2i+12i+1 for every positive integer ii . 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 will qq consecutive events happen soon. There are two types of events:

1. Government makes a new rule. A rule can be denoted by integers vv , uu and ww . As the result of this action, the passing fee of all roads on the shortest path from uu to vv increases by ww dollars.

2. Barney starts moving from some intersection vv and goes to intersection uu where 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).

输入格式

The first line of input contains a single integer qq ( 1<=q<=10001<=q<=1000 ).

The next qq lines contain the information about the events in chronological order. Each event is described in form 11 vv uu ww if it's an event when government makes a new rule about increasing the passing fee of all roads on the shortest path from uu to vv by ww dollars, or in form 22 vv uu if it's an event when Barnie goes to cuddle from the intersection vv to the intersection uu .

1<=v,u<=1018,vu,1<=w<=1091<=v,u<=10^{18},v≠u,1<=w<=10^{9} states for every description line.

输出格式

For each event of second type print the sum of passing fee of all roads Barney passes in this event, in one line. Print the answers in chronological order of corresponding events.

输入输出样例

  • 输入#1

    7
    1 3 4 30
    1 4 1 2
    1 3 6 8
    2 4 3
    1 6 1 40
    2 3 7
    2 2 4
    

    输出#1

    94
    0
    32
    

说明/提示

In the example testcase:

Here are the intersections used:

1. Intersections on the path are 33 , 11 , 22 and 44 .
2. Intersections on the path are 44 , 22 and 11 .
3. Intersections on the path are only 33 and 66 .
4. Intersections on the path are 44 , 22 , 11 and 33 . Passing fee of roads on the path are 3232 , 3232 and 3030 in order. So answer equals to 32+32+30=9432+32+30=94 .
5. Intersections on the path are 66 , 33 and 11 .
6. Intersections on the path are 33 and 77 . Passing fee of the road between them is 00 .
7. Intersections on the path are 22 and 44 . Passing fee of the road between them is 3232 (increased by 3030 in the first event and by 22 in the second).

首页