#C3698. Process Queries on an Array
Process Queries on an Array
Process Queries on an Array
In many programming contests, you are often required to process multiple queries on an array. In this problem, you are given an array (A) of (n) integers and (q) queries. Each query consists of three integers (t), (l), and (r) where (l) and (r) represent the starting and ending indices of a subarray (A[l \ldots r]). Depending on the value of (t), you need to perform one of the following operations:
- If (t = 1), compute the sum of the subarray: (S = \sum_{i=l}^{r} A_i).
- If (t = 2), find the maximum element in the subarray.
- If (t = 3), find the minimum element in the subarray.
Your task is to output the result for each query on a new line.
Note: The array indices are 0-based.
inputFormat
The input is read from standard input (stdin) and has the following format:
- 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 (A).
- Each of the next (q) lines contains three space-separated integers (t), (l), and (r) which describe a query.
outputFormat
For each query, output a single line containing the result of that query on standard output (stdout).## sample
5 3
1 3 -2 8 4
1 1 3
2 0 4
3 2 4
9
8
-2
</p>