311032: CF1924B. Space Harbour

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Space Harbourtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

There are $n$ points numbered $1$ to $n$ on a straight line. Initially, there are $m$ harbours. The $i$-th harbour is at point $X_i$ and has a value $V_i$. It is guaranteed that there are harbours at the points $1$ and $n$. There is exactly one ship on each of the $n$ points. The cost of moving a ship from its current location to the next harbour is the product of the value of the nearest harbour to its left and the distance from the nearest harbour to its right. Specifically, if a ship is already at a harbour, the cost of moving it to the next harbour is $0$.

Additionally, there are $q$ queries, each of which is either of the following $2$ types:

  • $1$ $x$ $v$ — Add a harbour at point $x$ with value $v$. It is guaranteed that before adding the harbour, there is no harbour at point $x$.
  • $2$ $l$ $r$ — Print the sum of the cost of moving all ships at points from $l$ to $r$ to their next harbours. Note that you just need to calculate the cost of moving the ships but not actually move them.
Input

The first line contains three integers $n$, $m$, and $q$ ($2 \le m \le n \le 3 \cdot 10^5$, $1 \le q \le 3 \cdot 10^5$) — the number of points, harbours, and queries, respectively.

The second line contains $m$ distinct integers $X_1, X_2, \ldots, X_m(1 \le X_i \le n)$ — the position at which the $i$-th harbour is located.

The third line contains $m$ integers $V_1, V_2, \ldots, V_m(1 \le V_i \le 10^7)$ — the value of the $i$-th harbour.

Each of the next $q$ lines contains three integers. The first integer is $t$ ($1\le t \le 2$) — type of query. If $t=1$, then the next two integers are $x$ and $v$ ($2 \le x \le n - 1$, $1 \le v \le 10^7$) — first-type query. If $t=2$, then the next two integers are $l$ and $r$ ($1 \le l \le r \le n$) — second-type query.

It is guaranteed that there is at least one second-type query.

Output

For every second-type query, print one integer in a new line — answer to this query.

ExampleInput
8 3 4
1 3 8
3 24 10
2 2 5
1 5 15
2 5 5
2 7 8
Output
171
0
15
Note

For the first type $2$ query, the cost for ships at positions $2$, $3$, $4$ and $5$ are $3(3 \times 1)$, $0$, $96(24 \times 4)$ and $72(24 \times 3)$ respectively.

For the second type $2$ query, since the ship at position $5$ is already at a harbour, so the cost is $0$.

For the third type $2$ query, the cost for ships at position $7$ and $8$ are $15(15 \times 1)$ and $0$ respectively.

Output

题目大意:
在一条直线上有n个点,编号为1到n。一开始有m个港口,第i个港口位于点Xi,并且有一个值Vi。保证点1和n上至少有一个港口。每个点上恰好有一艘船。将船从当前位置移动到下一个港口的成本是左侧最近的港口的价值与右侧最近的港口的距离的乘积。特别地,如果船已经在港口,移动到下一个港口的成本是0。

此外,还有q个查询,每个查询都是以下两种类型之一:
1. 1 x v - 在点x添加一个价值为v的港口。保证在添加港口之前,点x上没有港口。
2. 2 l r - 打印将点l到r上的所有船移动到它们下一个港口的总成本。注意,只需要计算移动船只的成本,而不实际移动它们。

输入数据格式:
第一行包含三个整数n、m和q(2≤m≤n≤3×10^5,1≤q≤3×10^5)——点的数量、港口的数量和查询的数量。
第二行包含m个不同的整数X1, X2, …, Xm(1≤Xi≤n)——第i个港口的位置。
第三行包含m个整数V1, V2, …, Vm(1≤Vi≤10^7)——第i个港口的价值。
接下来的q行,每行包含三个整数。第一个整数是t(1≤t≤2)——查询类型。如果t=1,则接下来的两个整数是x和v(2≤x≤n-1,1≤v≤10^7)——第一种类型的查询。如果t=2,则接下来的两个整数是l和r(1≤l≤r≤n)——第二种类型的查询。
保证至少有一个第二种类型的查询。

输出数据格式:
对于每个第二种类型的查询,打印一行一个整数——对该查询的答案。

示例:
输入:
8 3 4
1 3 8
3 24 10
2 2 5
1 5 15
2 5 5
2 7 8
输出:
171
0
15

注意:
对于第一个类型2的查询,位置2、3、4和5的船的成本分别是3(3×1)、0、96(24×4)和72(24×3)。
对于第二个类型2的查询,由于位置5的船已经在港口,所以成本是0。
对于第三个类型2的查询,位置7和8的船的成本分别是15(15×1)和0。题目大意: 在一条直线上有n个点,编号为1到n。一开始有m个港口,第i个港口位于点Xi,并且有一个值Vi。保证点1和n上至少有一个港口。每个点上恰好有一艘船。将船从当前位置移动到下一个港口的成本是左侧最近的港口的价值与右侧最近的港口的距离的乘积。特别地,如果船已经在港口,移动到下一个港口的成本是0。 此外,还有q个查询,每个查询都是以下两种类型之一: 1. 1 x v - 在点x添加一个价值为v的港口。保证在添加港口之前,点x上没有港口。 2. 2 l r - 打印将点l到r上的所有船移动到它们下一个港口的总成本。注意,只需要计算移动船只的成本,而不实际移动它们。 输入数据格式: 第一行包含三个整数n、m和q(2≤m≤n≤3×10^5,1≤q≤3×10^5)——点的数量、港口的数量和查询的数量。 第二行包含m个不同的整数X1, X2, …, Xm(1≤Xi≤n)——第i个港口的位置。 第三行包含m个整数V1, V2, …, Vm(1≤Vi≤10^7)——第i个港口的价值。 接下来的q行,每行包含三个整数。第一个整数是t(1≤t≤2)——查询类型。如果t=1,则接下来的两个整数是x和v(2≤x≤n-1,1≤v≤10^7)——第一种类型的查询。如果t=2,则接下来的两个整数是l和r(1≤l≤r≤n)——第二种类型的查询。 保证至少有一个第二种类型的查询。 输出数据格式: 对于每个第二种类型的查询,打印一行一个整数——对该查询的答案。 示例: 输入: 8 3 4 1 3 8 3 24 10 2 2 5 1 5 15 2 5 5 2 7 8 输出: 171 0 15 注意: 对于第一个类型2的查询,位置2、3、4和5的船的成本分别是3(3×1)、0、96(24×4)和72(24×3)。 对于第二个类型2的查询,由于位置5的船已经在港口,所以成本是0。 对于第三个类型2的查询,位置7和8的船的成本分别是15(15×1)和0。

加入题单

上一题 下一题 算法标签: