luogu#P8939. [DTOI 2023] B. 去年 11 月卵梦蕾简易钨丝
[DTOI 2023] B. 去年 11 月卵梦蕾简易钨丝
Background
The large sample has been fixed.

Problem Description
Given a sequence , it supports two types of operations of the form opt x.
-
1 x: Delete one number . If there is no in the sequence, output-1and skip this operation. If there are multiple , delete only one of them. -
2 x: Insert one number into the sequence.
For each operation that is not skipped, find a permutation of that minimizes , that is, minimize $\lvert p_2-p_1\rvert+\lvert p_3-p_2\rvert+\dots+\lvert p_{n+1}-p_n\rvert$, where .
It is guaranteed that at any time there is at least number in the sequence.
is a permutation of if and only if for all , .
In short, is the result of rearranging in some way.
For example, is a permutation of , but is not.
Input Format
The input has lines in total.
Line contains two positive integers .
Line contains non-negative integers , representing the initial sequence.
Lines to each contain two numbers , representing one query.
Output Format
There are multiple lines of output.
Each line outputs number, representing the answer for a query that is not ignored; otherwise output -1.
5 3
1 2 3 4 10
1 4
1 10
2 9
18
4
16
Hint
Sample 1 Explanation.
For the first query, the number is deleted from the sequence, so the current sequence is . It can be proven that is the minimum answer for the current sequence.
For the second query, the number is deleted from the sequence, so the current sequence is . It can be proven that is the minimum answer for the current sequence.
For the third query, the number is added to the sequence, so the current sequence is . It can be proven that is the minimum answer for the current sequence.
Sample 2.
See abs/abs2.in and abs/abs2.out in the additional files.
This sample satisfies the constraints of test points .
Sample 3.
See abs/abs3.in and abs/abs3.out in the additional files.
This sample satisfies the constraints of test points .
Constraints and Hints.
Let be the value range size. For all testdata, it is guaranteed that and .
The specific constraints for each test point are shown in the table below.
| Test Point ID | ||
|---|---|---|
Translated by ChatGPT 5