#SRD0000141. Giá trị nhỏ thứ k trong đoạn (Range Kth Smallest)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Giá trị nhỏ thứ k trong đoạn (Range Kth Smallest)
Range Kth Smallest
Source: Library Checker
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a sequence of nonnegative integers . The sequence is static.
Each query consists of integers . Take the elements from index through index , and sort these elements into nondecreasing order. Find the element at index , using zero-based indexing, in the sorted sequence; equivalently, the -th smallest value.
Equal elements are counted as separate occurrences; do not remove duplicates. The original sequence is also indexed from , and query intervals are half-open .
Answer all queries in input order.
Input
- The first line contains integers .
- The second line contains integers .
- Each of the next lines contains integers for query .
Output
Print lines. Line contains the -th smallest value in , counting repeated values separately.
Subtasks
- Subtask 1 (20 points): ; ; ; for every valid index.
- Subtask 2 (30 points): ; ; ; for every valid index.
- Subtask 3 (50 points): ; ; ; for every valid index.
Examples
Example 1
Input
5 3
1 4 0 1 3
0 5 2
1 3 1
3 4 0
Output
1
4
1
Explanation
The sequence is 1 4 0 1 3. Sorting [0,5) yields 0 1 1 3 4; rank has value 1. The elements of [1,3) are 4 0; sorting gives 0 4, and rank is 4. Interval [3,4) contains only 1, so rank returns 1. Both occurrences of value 1 in the first query are counted separately.