K’th Element (I)
Author: QuwsarOhi
Problem Setter: Abu Quwsar OhiIntake 33, Department of CSE
You
are given N sorted values and Q queries. Each query consists of three
values, l, r, and k. Each query
states that you have to find the k’th value from the given input starting from
index l to index r. Note that the index of N sorted value starts from index 1.
Input Format
The input starts with an integer N (N <= 105), defining the number of values. The next line
contains N sorted values (0 <=
values <= 109). The next line contains an integer Q (Q <= 105), defining the
number of queries.
The next Q lines
contain three space-separated integer l, r,
k, (l <= r and k <= r-l+1) defining
that you have to find the k’th element from the input value that lies in index l, to r. By k’th value, it is meant that if you sort the values starting
from index l to r, then you have to output the k’th value from the sorted values.
Output Format
For each query,
output the k’th value in a separated line.
Explanation:
The second
query asks you to find the 2nd
value from the N input
values, starting from the 2nd index value of the input to the 4th
index value. The sorted values on this index range are 13, 14 15. The 2nd
value is 14, which is the answer to the second query.
Samples
Input
Output
Language | Time | Memory |
GNU C 11 | 2s | 512MB |
GNU C++ 14 | 2s | 512MB |
GNU C++ 11 | 2s | 512MB |