#C6951. Range Minimum Query and Update
Range Minimum Query and Update
Range Minimum Query and Update
You are given an array of n integers and q queries. There are two types of queries:
- Update Query:
1 x y
– update the element at position x (1-indexed) to the value y. - Range Minimum Query:
2 l r
– find the minimum element in the range from l to r (inclusive).
For each query of the second type, output the minimum element in the specified range. If there are no range queries, output nothing.
Note: The queries are provided in order. The array indices are 1-indexed.
The fundamental idea behind an efficient solution is to use a segment tree which supports both range queries and point updates in O(log n) time.
The mathematical definition of the range minimum query can be stated in LaTeX as follows:
$$ \min_{i=l}^{r} a_i $$
inputFormat
The input is read from stdin and consists of the following:
- The first line contains two integers
n
andq
— the number of elements in the array and the number of queries. - The second line contains
n
space-separated integers representing the initial array. - The next
q
lines each contain a query in one of the two formats described above.
outputFormat
For each range minimum query (queries of type 2), output the minimum value found in the specified range on a new line. The output is written to stdout.
## sample5 5
5 4 3 2 1
2 1 5
1 3 9
2 1 5
2 3 4
1 5 0
1
1
2
</p>