SP26319 ILKQUERY - I LOVE Kd-TREES
Description
You've been invited to the "I-Love-Kd-trees'' annual con, but first, you have to show them that you really know about great data structures, so they give you an easy task!
You are given a list of **N** numbers and **Q** queries, each query consist of three integers: _**k**,_ **_i_** and **_l_** ;let **d** be the **k-th** smallest element until the index **i** (i.e. if the first i+1 elements were sorted in non-descending way, **d** would be the element at index **k - 1** ). Then, the answer to each query is the index of the **l-th** occurrence of **d** in the array. If there's no such index, the answer is **-1.** You have to consider that all indexes are counted starting with 0.
Input Format
Input consists of one test case.
The first line contains two integers, **N** ( 1 Q (1
The next line contains **N** possibly distinct integers **a $ _{i} $** ( -10 $ ^{9} $
Then **Q** lines follow, each of those contains three integers _**k**_, _**i**_ and _**l**_. (0 < k
Output Format
For each query (in the same order as the input) output a single line with the answer to that query.
Explanation/Hint
Explanation of the first query:
The elements until index 4 are [2, 6, 7, 1, 8] so the 2nd smallest element is 2, and your asked for the index of its 2nd occurrence, so the answer is 6.