#K53352. Segment Tree Range Queries

    ID: 29512 Type: Default 1000ms 256MiB

Segment Tree Range Queries

Segment Tree Range Queries

You are given an array \(A = [a_1, a_2, \ldots, a_n]\) of \(n\) integers. You need to process \(q\) queries on this array. There are three types of queries:

  • Q L R: Output the sum of the numbers in the segment \(a_L, a_{L+1}, \ldots, a_R\).
  • M L R: Output the minimum element in the segment \(a_L, a_{L+1}, \ldots, a_R\).
  • U i x: Update the \(i\)-th element of the array to \(x\).

Note that the indices are 1-indexed.

You are encouraged to use a segment tree to support these operations efficiently.

inputFormat

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

  1. The first line contains an integer \(n\) representing the number of elements in the array.
  2. The second line contains \(n\) space-separated integers, the elements of the array \(A = [a_1, a_2, \ldots, a_n]\).
  3. The third line contains an integer \(q\) representing the number of queries.
  4. The following \(q\) lines each contain a query in one of the following formats:
    • Q L R for a sum query;
    • M L R for a minimum query;
    • U i x for an update query.

outputFormat

For each query of type Q or M, output the result on a separate line in the order that the queries appear in the input. Update queries do not produce an output.

## sample
5
1 2 3 4 5
5
Q 1 3
M 2 4
U 3 10
Q 1 3
M 2 4
6

2 13 2

</p>