QOJ.ac

QOJ

時間限制: 3 s 記憶體限制: 256 MB 總分: 100

#13822. Report Statistics

统计

Xiao Q's mother is a cashier who often needs to prepare statistical reports. Today is her birthday, and Xiao Q hopes to help her with some of her work as a birthday gift.

After careful observation, Xiao Q discovered that preparing a report actually involves maintaining a sequence of non-negative integers and performing several query operations.

Initially, there is a sequence of integers of length $N$, and there are three types of operations:

Operation Description
INSERT i k Insert a new element $k$ after the $i$-th element of the original sequence; if several elements have already been added after the $i$-th element of the original sequence, add it after those elements (see the example below).
MIN_GAP Query the minimum absolute difference between adjacent elements.
MIN_SORT_GAP Query the minimum absolute difference between any two elements in the entire sequence.

For example, if the initial sequence is: 5 3 1

Executing the operation INSERT 2 9 results in: 5 3 9 1 At this point, MIN_GAP is 2, and MIN_SORT_GAP is 2.

Executing the operation INSERT 2 6 results in: 5 3 9 6 1 Note that at this time, a 9 has already been added after the 2nd element of the original sequence, so the newly added 6 should be placed after the 9. At this point, MIN_GAP is 2, and MIN_SORT_GAP is 1.

Xiao Q wrote a program to automatically complete these operations, but he found that his program runs very slowly for some large reports. Can you help him improve the program?

Input

The first line contains two integers $N$ and $M$, representing the length of the original sequence and the number of operations, respectively.

The second line contains $N$ integers, which is the initial sequence.

The next $M$ lines each contain an operation, which is one of INSERT i k, MIN_GAP, or MIN_SORT_GAP (with no extra spaces or empty lines).

Output

For each MIN_GAP and MIN_SORT_GAP command, output the answer on a single line.

Examples

Input 1

3 5
5 3 1
INSERT 2 9
MIN_SORT_GAP
INSERT 2 6
MIN_GAP
MIN_SORT_GAP

Output 1

2
2
1

Constraints

For 30% of the data, $N \le 1000, M \le 5000$.

For 100% of the data, $N, M \le 500000$.

For all data, the integers in the sequence do not exceed $5 \times 10^8$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.