#SGM0000069. Số nhỏ thứ k (K-th Number)
Số nhỏ thứ k (K-th Number)
K-th Number
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem
For every query , return the -th smallest value of the distinct integers in subarray .
Input
The first line contains , followed by the array and then lines .
Output
Print one answer per query.
Subtasks
Subtask 1 (20%)
- , number of queries .
- All other conditions are the same as Subtask 3.
Subtask 2 (30%)
- , number of queries .
- All other conditions are the same as Subtask 3.
Subtask 3 (50%)
- and all values are distinct
Example
Input
7 3
1 5 2 6 3 7 4
2 5 3
4 4 1
1 7 3
Output
5
6
3
Explanation
Sorting [5,2,6,3] gives [2,3,5,6]; the third value is .