#P1924B. Space Harbour
Space Harbour
Description
There are points numbered to on a straight line. Initially, there are harbours. The -th harbour is at point and has a value . It is guaranteed that there are harbours at the points and . There is exactly one ship on each of the 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 .
Additionally, there are queries, each of which is either of the following types:
- — Add a harbour at point with value . It is guaranteed that before adding the harbour, there is no harbour at point .
- — Print the sum of the cost of moving all ships at points from to to their next harbours. Note that you just need to calculate the cost of moving the ships but not actually move them.
The first line contains three integers , , and (, ) — the number of points, harbours, and queries, respectively.
The second line contains distinct integers — the position at which the -th harbour is located.
The third line contains integers — the value of the -th harbour.
Each of the next lines contains three integers. The first integer is () — type of query. If , then the next two integers are and (, ) — first-type query. If , then the next two integers are and () — second-type query.
It is guaranteed that there is at least one second-type query.
For every second-type query, print one integer in a new line — answer to this query.
Input
The first line contains three integers , , and (, ) — the number of points, harbours, and queries, respectively.
The second line contains distinct integers — the position at which the -th harbour is located.
The third line contains integers — the value of the -th harbour.
Each of the next lines contains three integers. The first integer is () — type of query. If , then the next two integers are and (, ) — first-type query. If , then the next two integers are and () — 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.
Note
For the first type query, the cost for ships at positions , , and are , , and respectively.
For the second type query, since the ship at position is already at a harbour, so the cost is .
For the third type query, the cost for ships at position and are and respectively.