#P16214. [ECUSTPC 2025] 午夜季风

    ID: 18229 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>平衡树2025高校校赛

[ECUSTPC 2025] 午夜季风

Problem Description

There are nn pufferfish in front of Maddy. Each pufferfish has a size value aia_i. Pufferfish with very different sizes will explode when placed together, so Maddy decides to arrange them in a line. Let the sizes from left to right after arranging be a1,a2,,ana_1', a_2', \dots, a_n'. Then Maddy defines the explosion level of this line of pufferfish as

$$B = \sum \limits_{i < j, |i - j| > 1} |a_i' - a_j'|$$

Now the pufferfish change at midnight. Specifically, there are mm transformations. In each transformation, the size of one pufferfish idid increases by deltdelt (when delt<0delt < 0, the pufferfish size decreases by delt|delt|). After each transformation, Maddy wants you to find an arrangement of the pufferfish in a line that minimizes the explosion level, and you need to output the corresponding explosion level BB.
Note that each transformation has a lasting effect, meaning the effect of the previous transformation remains and will affect subsequent computations and transformations.
Also note that pufferfish sizes can be negative.

Input Format

The first line contains an integer TT (1T1051 \le T \le 10^5), indicating the number of test cases.
For each test case, the first line contains two integers nn and mm (2n105,1m1052 \le n \le 10^5, 1 \le m \le 10^5), representing the number of pufferfish and the number of transformations.
The next line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (108ai108-10^8 \le a_i \le 10^8), representing the sizes of the pufferfish. Note that pufferfish sizes can be negative.
Then follow mm lines, each containing two integers idid and deltdelt (1idn,108delt1081 \le id \le n, -10^8 \le delt \le 10^8), indicating the index of the pufferfish and the change in its size for each transformation.
It is guaranteed that for each test case, delt108\sum |delt| \le 10^8, and over all input testdata, n\sum n and m\sum m are both at most 3×1053 \times 10^5.

Output Format

For each test case, output one integer BB per line for each transformation, representing the minimum possible explosion level among all arrangements after that transformation.

1
4 3
1 2 3 4
4 0
2 5
1 -2
3
6
8

Hint

Sample 1 Explanation

After the first transformation, the pufferfish sizes are still {1,2,3,4}\{1, 2, 3, 4\}. The optimal arrangement is {2,4,1,3}\{2, 4, 1, 3\}, and the explosion level is $B = |a_1 - a_3| + |a_1 - a_4| + |a_2 - a_4| = |2 - 1| + |2 - 3| + |4 - 3| = 3$。
After the second transformation, the pufferfish sizes are {1,7,3,4}\{1, 7, 3, 4\}. The optimal arrangement is {3,7,1,4}\{3, 7, 1, 4\}, and the explosion level is $B = |a_1 - a_3| + |a_1 - a_4| + |a_2 - a_4| = |3 - 1| + |3 - 4| + |7 - 4| = 6$。
After the third transformation, the pufferfish sizes are {1,7,3,4}\{-1, 7, 3, 4\}. The optimal arrangement is {3,7,1,4}\{3, 7, -1, 4\}, and the explosion level is $B = |a_1 - a_3| + |a_1 - a_4| + |a_2 - a_4| = |3 - (-1)| + |3 - 4| + |7 - 4| = 8$。

Translated by ChatGPT 5