Codeforces Round 362 (Div. 2)
C
Lorenzo Von Matterhorn
Codeforces
未评级
原题
← BD →
翻译中…

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

翻译中…

image

翻译中…

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

翻译中…
  1. Government makes a new rule. A rule can be denoted by integers $*v*$, $*u*$ and $*w*$. As the result of this action, the passing fee of all roads on the shortest path from $*u*$ to $*v*$ increases by $*w*$ dollars.
翻译中…
  1. Barney starts moving from some intersection $*v*$ and goes to intersection $*u*$ 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).

翻译中…

Input

翻译中…

The first line of input contains a single integer $*q*$ ($1 ≤ *q* ≤ 1 000$).

翻译中…

The next $*q*$ lines contain the information about the events in chronological order. Each event is described in form $1$ $*v*$ $*u*$ $*w*$ if it's an event when government makes a new rule about increasing the passing fee of all roads on the shortest path from $*u*$ to $*v*$ by $*w*$ dollars, or in form $2$ $*v*$ $*u*$ if it's an event when Barnie goes to cuddle from the intersection $*v*$ to the intersection $*u*$.

翻译中…

$1 ≤ *v*, *u* ≤ 10^{18}, *v* ≠ *u*, 1 ≤ *w* ≤ 10^{9}$ states for every description line.

翻译中…

Output

翻译中…

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.

翻译中…

Note

翻译中…

In the example testcase:

翻译中…

Here are the intersections used:

翻译中…

image

翻译中…
  1. Intersections on the path are $3$, $1$, $2$ and $4$.
  2. Intersections on the path are $4$, $2$ and $1$.
  3. Intersections on the path are only $3$ and $6$.
  4. Intersections on the path are $4$, $2$, $1$ and $3$. Passing fee of roads on the path are $32$, $32$ and $30$ in order. So answer equals to $32 + 32 + 30 = 94$.
  5. Intersections on the path are $6$, $3$ and $1$.
  6. Intersections on the path are $3$ and $7$. Passing fee of the road between them is $0$.
  7. Intersections on the path are $2$ and $4$. Passing fee of the road between them is $32$ (increased by $30$ in the first event and by $2$ in the second).
翻译中…

样例

Input #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
Output #1
94
0
32
InputCopy OutputCopy
题目信息
题号
697C
时间限制
1 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。