#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 nn points with houses built. The coordinates of these houses are x1,x2,...,xnx_1, x_2, ..., x_n, and in the ii-th house there live viv_i 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 ii is affected. Then the "inconvenience" of building the shelter at zz is vixizv_i*|x_i-z|.)

Of course, the Human Village in Gensokyo cannot stay unchanged, so both house positions and resident counts may change.

Specifically, you need to process mm queries or modifications. Each input is in one of the following formats:

  • 1 l r: Query, when the houses whose coordinates lie in [l,r][l, r] are affected by the incident, among all ways to build a shelter, what is the minimum possible "inconvenience".

  • 2 a b c: Modify the aa-th house: change its coordinate to bb, and change the number of residents living in it to cc.

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 aa-th house, not the house whose coordinate is aa.

Input Format

The first line contains two integers, n,mn, m.

The second line contains nn integers, xix_i.

The third line contains nn integers, viv_i.

The next mm 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 x=4x=4 with 33 residents, and one at x=7x=7 with 66 residents.

When the shelter is built at x=7x=7, 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 99 is the minimum "inconvenience" among all ways to build a shelter.


[Constraints]

  • For 100%100\% of the data:

    1n,m3×1051 \le n, m \le 3 \times 10 ^ 5.

    1an1 \le a \le n, 109lr109-10 ^ 9 \le l \le r \le 10 ^ 9, 109xi,b109-10 ^ 9 \le x_i, b \le 10 ^ 9, 0vi,c1030 \le v_i, c \le 10 ^ 3.

  • Detailed constraints:

    Let mxmx be the maximum absolute value among all input integers.

    Test point ID n,mn, m \le mxmx \le Score
    11 100100 1010
    22 8×1038 \times 10 ^ 3 8×1038 \times 10 ^ 3 1515
    33 10910 ^ 9 55
    44 10510 ^ 5 10510 ^ 5 3030
    55 10910 ^ 9 1010
    66 3×1053 \times 10 ^ 5 3030

Translated by ChatGPT 5