#K64447. Timestamp Queries
Timestamp Queries
Timestamp Queries
You are given a list of N timestamps corresponding to particular actions in a log, and Q queries. Each query is one of two types:
- E: Find the earliest (minimum) timestamp in the subarray.
- L: Find the latest (maximum) timestamp in the subarray.
Each query gives you two indices, L and R (0-indexed), and you need to process the query over the range $[L, R]$. In mathematical notation, for a query of type E you must compute $$ \min_{i=L}^{R}\,T[i] $$ and for a query of type L, you must compute $$ \max_{i=L}^{R}\,T[i] $$ where $T$ is the list of timestamps.
Your task is to answer each query and print out the answer for each on a new line.
inputFormat
The input is read from stdin and has the following format:
N Q T1 T2 ... TN C1 L1 R1 C2 L2 R2 ... (Q queries in total)
Where:
N
is the number of timestamps.Q
is the number of queries.- The second line contains
N
integers representing the timestamps. - Each of the next
Q
lines contains a characterC
(either 'E' or 'L') and two integersL
andR
representing the range for the query. The indices are 0-indexed.
outputFormat
For each query, output the requested value on a new line to stdout.
## sample6 3
10 5 3 7 2 8
E 1 4
L 0 2
E 2 5
2
10
2
</p>