#P6011. Array Deletion and Range Query
Array Deletion and Range Query
Array Deletion and Range Query
You are given an array with \( n \) elements. You need to perform two types of operations on this array:
DELETE k
: Delete the element at position \( k \) (1-indexed). All elements to its right shift one position to the left.QUERY i j
: Query the segment from positions \( i \) to \( j \) (inclusive) and output the minimum and maximum values in this range.
For example, consider an array with 10 elements:
Position | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
---|---|---|---|---|---|---|---|---|---|---|
Element | 1 | 5 | 2 | 6 | 7 | 4 | 9 | 3 | 1 | 5 |
The result of QUERY 2 8
is 2 9
(since the minimum is \(2\) and the maximum is \(9\)).
After executing DELETE 3
and DELETE 6
(note that the deletions refer to the positions in the original array), the array becomes:
Position | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
---|---|---|---|---|---|---|---|---|
Element | 1 | 5 | 6 | 7 | 4 | 3 | 1 | 5 |
Now, QUERY 2 8
yields 1 7
.
Note: All formulas must be written in LaTeX format, for example \( n \), \( k \), \( i \), and \( j \).
inputFormat
The first line contains two integers \( n \) and \( m \), where \( n \) is the number of elements in the array and \( m \) is the number of operations.
The second line contains \( n \) space-separated integers representing the elements of the array.
The following \( m \) lines each contain an operation in one of the following formats:
DELETE k
QUERY i j
It is guaranteed that the operations are valid and positions are 1-indexed.
outputFormat
For each QUERY
operation, output a line containing two space-separated integers representing the minimum and maximum values in the specified range.
sample
10 4
1 5 2 6 7 4 9 3 1 5
QUERY 2 8
DELETE 3
DELETE 6
QUERY 2 8
2 9
1 7
</p>