#P6309. 「Wdsr-1」人间之里
「Wdsr-1」人间之里
Description
Although the Human Village can be said to be the safest place for humans in all of Gensokyo, accidents may still happen when an incident occurs, so shelters need to be built.
The Human Village can be abstracted as a coordinate axis, on which there are points with houses built. The coordinates of these houses are , and in the -th house there live residents.
Each time an incident occurs, a coordinate-contiguous segment of houses will be affected, and then it is necessary to build a shelter at some coordinate. The "inconvenience" of a shelter is the sum, over every resident in the affected houses, of their distance to the shelter.
(For example, suppose only house is affected. Then the "inconvenience" of building the shelter at is .)
Of course, the Human Village in Gensokyo cannot stay unchanged, so both house positions and resident counts may change.
Specifically, you need to process queries or modifications. Each input is in one of the following formats:
-
1 l r: Query, when the houses whose coordinates lie in are affected by the incident, among all ways to build a shelter, what is the minimum possible "inconvenience". -
2 a b c: Modify the -th house: change its coordinate to , and change the number of residents living in it to .
Notes:
-
In operation
1, the "affected by the incident" is only a hypothesis, so it does not affect later queries. -
In operation
2, the changed object is the -th house, not the house whose coordinate is .
Input Format
The first line contains two integers, .
The second line contains integers, .
The third line contains integers, .
The next lines each describe one operation.
Output Format
For each 1 l r operation, output the minimum "inconvenience" for building the shelter.
10 10
-2 -3 -7 2 -6 7 -3 -5 4 -7
0 2 2 0 4 6 2 4 3 3
1 4 7
1 -5 7
1 -1 8
2 8 9 2
2 7 -3 5
2 7 4 3
2 2 -1 7
1 -9 -7
2 2 3 1
1 -1 0
9
82
9
0
0
Hint
[Sample Explanation]
For the first query, there are two houses affected: one at with residents, and one at with residents.
When the shelter is built at , the "inconvenience" is:
$$\left\vert 7 - 4 \right\vert \times 3 + \left\vert 7 - 7 \right\vert \times 6 = 9$$It can be proven that is the minimum "inconvenience" among all ways to build a shelter.
[Constraints]
-
For of the data:
.
, , , .
-
Detailed constraints:
Let be the maximum absolute value among all input integers.
Test point ID Score
Translated by ChatGPT 5
京公网安备 11011102002149号