#K92272. Minimum Element in Subarray

    ID: 38161 Type: Default 1000ms 256MiB

Minimum Element in Subarray

Minimum Element in Subarray

You are given an array \(A\) of \(n\) integers and \(q\) queries. Each query consists of two integers \(l\) and \(r\) representing the range of indices (1-indexed). For each query, determine the minimum element in the subarray \(A[l \ldots r]\).

Input Format:

  • The first line contains an integer \(n\) which is the size of the array.
  • The second line contains \(n\) space-separated integers representing the elements of the array \(A\).
  • The third line contains an integer \(q\), the number of queries.
  • Each of the next \(q\) lines contains two space-separated integers \(l\) and \(r\) representing a query.

Output Format:

  • For each query, print the minimum element in the subarray \(A[l \ldots r]\) on a new line.

Note: The queries use 1-indexed positions while arrays in most programming languages are 0-indexed. Ensure that you adjust the indices accordingly when processing the queries.

inputFormat

The input is read from stdin. The first line contains an integer n (the number of elements in the array). The second line contains n space-separated integers representing the array elements. The third line contains an integer q (the number of queries). The following q lines each contain two space-separated integers l and r representing the 1-indexed start and end indices of a query.

outputFormat

For each query, output a single line with the minimum element found in the subarray from index l to r.## sample

5
2 5 1 4 3
1
1 3
1