#K78282. Taco Segment Tree Query

    ID: 35052 Type: Default 1000ms 256MiB

Taco Segment Tree Query

Taco Segment Tree Query

You are given an array of n integers. Your task is to process q queries on the array. There are two types of queries:

  • 1 l r: Return the minimum value in the subarray spanning indices l to r (1-indexed).
  • 2 i x: Update the element at index i to the new value x.

This problem can be efficiently solved using a Segment Tree. In a segment tree, the value at each internal node is computed using the recurrence relation:

$\text{tree}[i] = \min(\text{tree}[2i],\; \text{tree}[2i+1])$

Implement the operations so that all queries can be answered efficiently.

inputFormat

The first line contains two integers n and q, representing the number of elements in the array and the number of queries, respectively. The second line contains n space-separated integers representing the array elements. The next q lines each describe a query in one of the following formats:

  1. For a range minimum query: 1 l r where 1 ≤ l ≤ r ≤ n.
  2. For an update query: 2 i x where 1 ≤ i ≤ n and x is the new value to set at index i.

Note: Array indices are 1-indexed.

outputFormat

For each query of the first type (range minimum query), output the minimum value found in the specified range. Each result should be printed on a separate line in the order the queries appear.## sample

5 3
5 3 8 6 2
1 2 4
2 3 1
1 1 5
3

1

</p>