#K91192. Range Minimum Query with Updates

    ID: 37921 Type: Default 1000ms 256MiB

Range Minimum Query with Updates

Range Minimum Query with Updates

You are given an array of n integers and a sequence of q operations. Each operation is one of the following two types:

  1. Update: "1 i x" – update the array so that the element at index i (1-indexed) is changed to x.
  2. Query: "2 l r" – report the minimum value in the subarray from index l to index r (inclusive, 1-indexed).

Your task is to process all the operations and print the results of the query operations. The problem can be solved efficiently by using a segment tree to handle the range minimum queries and point updates.

Note: All indices are 1-indexed.

The range minimum query is defined mathematically as follows:

\[ \min_{l \leq i \leq r} A_i \]

inputFormat

The first line of input contains two integers n and q, representing the number of elements in the array and the number of operations, respectively.

The second line contains n space-separated integers representing the initial array.

The following q lines each contain an operation in one of the two formats:

  • "1 i x" – update operation: assign the value x at position i.
  • "2 l r" – query operation: output the minimum value in the range [l, r].

outputFormat

For each query operation (of type "2 l r"), print the answer (the minimum value in the given range) on a separate line.

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

3 1

</p>