#P1110. [ZJOI2007] 报表统计
[ZJOI2007] 报表统计
Description
Little Q’s mother is a cashier and often needs to prepare statistical reports. Today is her birthday, and Little Q wants to help with some of the work as a birthday present.
After careful observation, Little Q finds that preparing a report is essentially maintaining a sequence of non-negative integers and performing some queries.
Initially, there is an integer sequence of length , and the following three operations are supported:
INSERT i k: Append a new element immediately after the -th element of the original sequence. If some elements have already been appended after the -th original element, append after all those appended elements (see the sample explanation).MIN_GAP: Query the minimum absolute difference between any two adjacent elements.MIN_SORT_GAP: Query the minimum absolute difference between the two closest elements among all elements.
Little Q wrote a program to automate these operations, but it runs slowly on large reports. Can you help improve it?
Input Format
- The first line contains two integers, the length of the original sequence and the number of operations .
- The second line contains integers, the initial sequence; the -th integer is .
- The next lines each contain one operation, which is one of
INSERT i k,MIN_GAP, orMIN_SORT_GAP(no extra spaces or blank lines).
Output Format
For each MIN_GAP and MIN_SORT_GAP command, output the answer on its own line.
3 5
5 3 1
INSERT 2 9
MIN_SORT_GAP
INSERT 2 6
MIN_GAP
MIN_SORT_GAP
2
2
1
Hint
Explanation of Sample Input/Output 1
The initial sequence is .
After performing INSERT 2 9, the sequence becomes . At this time, MIN_GAP is , and MIN_SORT_GAP is .
Next, performing INSERT 2 6 yields .
Note that by this time one has already been appended after the 2nd element of the original sequence, so the newly inserted should be placed after . Now MIN_GAP is , and MIN_SORT_GAP is .
Constraints
For all test points, it is guaranteed that , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号