#C9512. Dynamic Array Range Minimum Query

    ID: 53614 Type: Default 1000ms 256MiB

Dynamic Array Range Minimum Query

Dynamic Array Range Minimum Query

You are given an array of N integers and Q operations to perform on the array. There are two types of operations:

  • Update Operation: Given in the form 1 x y, update the element at index x in the array to the value y.
  • Query Operation: Given in the form 2 l r, output the minimum value in the subarray from index l to r (inclusive).

You are required to perform these operations in the given order and output the result for each query operation.

Note: The queries and updates are performed on a 0-indexed array.

The solution must process the operations efficiently. A segment tree is a typical data structure to achieve this in \(O(\log N)\) time per operation.

inputFormat

The input is given from standard input (stdin) and has the following format:

N Q
a0 a1 ... aN-1
op1
op2
...
opQ

Here:

  • N is the number of elements in the array.
  • Q is the number of operations to perform.
  • The next line contains N space-separated integers, which are the elements of the array.
  • Each of the following Q lines represents an operation in one of two forms:
    • 1 x y — update the element at index x to the value y.
    • 2 l r — output the minimum element in the subarray from index l to r (inclusive).

outputFormat

For each query operation (of the form 2 l r), print the corresponding minimum value from the specified subarray on a new line to standard output (stdout).

## sample
5 5
1 3 2 7 9
2 1 3
1 2 6
2 1 3
2 0 4
1 4 1
2

3 1

</p>