#C5288. Segment Tree Operations
Segment Tree Operations
Segment Tree Operations
This problem requires you to implement a segment tree that supports point updates and range minimum queries. Given an array \(a\) of \(n\) integers, you will perform a series of operations of two types:
- Update Operation (type 1): Update the element at a specified index \(i\) to a new value \(x\). That is, set \(a_i = x\).
- Query Operation (type 2): Query the minimum value of the subarray from index \(l\) to index \(r\) (inclusive), i.e. compute \(\min_{l \leq i \leq r} a_i\).
You are guaranteed that all indices in the operations are valid.
Note: When a query operation is performed and there are no queries (for instance, if all operations are updates), no output is expected for that test case.
inputFormat
The input is given from standard input and has the following format:
The first line contains an integer n, denoting the number of elements in the array. The second line contains n space-separated integers, the initial values of the array. The third line contains an integer m, the number of operations. Then m lines follow, each representing an operation. An operation is described as follows:
- For an update operation, the line starts with 1 followed by two integers i and x, meaning update the element at index i (0-indexed) to x.
- For a query operation, the line starts with 2 followed by two integers l and r, meaning output the minimum value in the range [l, r] (inclusive).
Indices are 0-indexed.
outputFormat
For each query operation (type 2), output the minimum value in the specified range on a separate line. If there are no query operations, output nothing.## sample
5
10 2 5 7 4
4
2 1 3
1 2 1
2 1 3
2 0 4
2
1
1
</p>