#C2506. Range Minimum Query with Segment Tree

    ID: 45830 Type: Default 1000ms 256MiB

Range Minimum Query with Segment Tree

Range Minimum Query with Segment Tree

You are required to implement a segment tree data structure capable of efficiently handling point updates and answering range minimum queries. Given an array of integers, you must build the segment tree, process update operations that change the value at a specific position, and respond to queries that ask for the minimum value in a given sub-array.

For a range query, the answer should be the minimum value in the interval \( [l, r] \). For an update query, the element at the specified position should be updated to a new value.

Note: All indices provided in queries are 1-indexed, but you may choose to convert them to 0-indexing as per your implementation needs.

inputFormat

The first line contains two integers \( n \) and \( q \), where \( n \) is the number of elements in the array and \( q \) is the number of queries.

The second line contains \( n \) space-separated integers representing the array.

The next \( q \) lines each contain a query, which can be in one of the two formats:

  • 1 x y: Update the element at position \( x \) (1-indexed) to \( y \).
  • 2 l r: Output the minimum element in the range from \( l \) to \( r \) (inclusive, 1-indexed).

outputFormat

For each query of the second type, print the minimum value in the specified range on a new line.

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

2 1

</p>