#P7549. [BJWC2017] 神秘物质
[BJWC2017] 神秘物质
Description
One day, Xiao Cheng had just obtained a strange meteorite sample from the institute, and he could not wait to start observing it. Under the view of precise instruments, every atom that made up the meteorite was extremely clear.
Xiao Cheng found that these atoms were arranged into several columns, and the structure of each column was highly similar. Therefore, he decided to measure and test a single column of atoms.
The chosen column contains atoms arranged in order. Initially, the -th atom has energy . As time passes and due to manual tests, this column of atoms will undergo two kinds of observable changes:
merge x e: merge the current -th atom and the -th atom, obtaining a new atom with energy ;insert x e: insert a new atom with energy between the current -th atom and the -th atom.
For a column of atoms, what Xiao Cheng cares about is the energy difference between the atoms with the maximum energy and the minimum energy in a contiguous segment, which is called the interval range. Therefore, besides observing the changes, Xiao Cheng also often needs to compute two kinds of statistics on this column of atoms:
max x y: the maximum value of the interval range over all subintervals within the current atoms from position to position ;min x y: the minimum value of the interval range over all subintervals within the current atoms from position to position .
Here, a subinterval means a contiguous segment with length at least .
Xiao Cheng firmly believes this research can win the Nobel Prize in Physics. To help Xiao Cheng fulfill his wish as soon as possible, can you help him implement the above observations and measurements?
Input Format
The first line contains two integers , representing the initial number of atoms and the total number of events.
The second line contains integers separated by spaces, representing the energy of each atom in order.
The next lines each contain a string and two integers, describing one event. The format is the same as in the problem description.
Output Format
Output several lines. In order, each line should be the result for each max and min event.
4 3
5 8 10 2
max 1 3
min 1 3
max 2 4
5
2
8
Hint
Constraints
For of the testdata, , , .
Let be the current number of atoms:
- For
mergeevents, . - For
insertevents, . - For
maxandminevents, .
At any time, it is guaranteed that .
Translated by ChatGPT 5
京公网安备 11011102002149号