PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000070. Số nhỏ thứ k trong một đoạn (MKTHNUM - K-th Number)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Số nhỏ thứ k trong một đoạn (MKTHNUM - K-th Number)
MKTHNUM - K-th Number
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of pairwise distinct integers, each query asks for the -th smallest value among the elements in the inclusive subarray .
Input
The first line contains . The second contains distinct integers. Each of the next lines contains .
Output
For each query, print the original value of the -th smallest element, not its compressed rank.
Subtasks
Original constraints: ; ; ; all distinct; ; .
- Subtask 1 (20 points): ; ; ; all elements distinct; , .
- Subtask 2 (30 points): ; ; ; all elements distinct; , .
- Subtask 3 (50 points): ; ; ; all elements distinct; , .
Examples
Input
7 3
1 5 2 6 3 7 4
2 5 3
4 4 1
1 7 3
Output
5
6
3
Explanation
The subarray sorts to , whose third smallest element is .