Problems > K-th Smallest in a Slice

K-th Smallest in a Slice

Difficulty: 2200 6000 ms 128 MB

binary-search segment-tree

Answer Q queries (l, r, k): the k-th smallest element of al..r. The array is static.

Input: the first line has N and Q; the second line has the array; the next Q lines have l r k.

Output: one line per query.

Constraints:

  • 1 ≤ N, Q ≤ 105
  • |values| ≤ 106

Sample Tests

Input 1
5 2
5 1 4 2 3
2 4 2
1 5 5
Output 1
2
5
Input 2
1 1
9
1 1 1
Output 2
9

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.