#C6437. Range Minimum Query with Updates

    ID: 50197 Type: Default 1000ms 256MiB

Range Minimum Query with Updates

Range Minimum Query with Updates

You are given an integer array \(A = [a_1, a_2, \ldots, a_N]\) and you need to perform \(Q\) queries on it. There are two types of queries:

  • UPDATE i x: Update the \(i\)th element of the array to \(x\), i.e. perform \(a_i = x\). Note that the array is 1-indexed.
  • MIN l r: Output the minimum element in the subarray \(A[l \ldots r]\), i.e. compute \(\min\{a_l, a_{l+1}, \ldots, a_r\}\).

The input contains multiple test cases. For each test case, you will be given the size of the array, the elements of the array, and the queries to execute. For every query of type MIN, output the result on a new line.

inputFormat

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

T
N
a1 a2 ... aN
Q
Query 1
Query 2
... 
Query Q
... (repeated for T test cases)

Where:

  • T is the number of test cases.
  • For each test case, the first integer \(N\) denotes the size of the array \(A\).
  • Next, \(N\) space-separated integers represent the array elements.
  • The next integer \(Q\) is the number of queries.
  • Each of the following \(Q\) lines is a query, either in the form "UPDATE i x" or "MIN l r".

outputFormat

For each query of type MIN, print the result (the minimum element in the specified subarray) on a new line using standard output (stdout).

## sample
3
5
1 3 5 7 9
5
MIN 1 3
UPDATE 2 6
MIN 1 3
UPDATE 3 4
MIN 1 5
3
10 20 30
3
MIN 1 3
UPDATE 2 5
MIN 1 3
6
7 2 3 4 5 6
3
UPDATE 1 9
MIN 1 3
UPDATE 2 8
1

1 1 10 5 2

</p>