#P3730. 曼哈顿交易
曼哈顿交易
Description
- people line up in a row. For simplicity, each person holds exactly one stock.
- Different people may hold the same stock.
- Define the popularity of a stock as the number of people who hold that stock.
- Each time, Will will ask a query: among the people in a contiguous interval, what is the popularity of the stock with the -th smallest popularity?
Input Format
- The first line contains two positive integers , representing the number of people and the number of queries.
- The next line contains positive integers, where is the stock held by the -th person.
- The next lines each contain three positive integers , representing a query asking for the -th smallest popularity in the interval . It is guaranteed that .
Output Format
- For each query, output one integer on a separate line, which is the -th smallest popularity value in the interval .
- If is greater than the number of distinct stocks in the interval, output .
4 4
2 3 3 3
1 4 1
1 4 2
1 3 2
1 3 3
1
3
2
-1
Hint
For of the testdata, .
For another of the testdata, all queries have .
For of the testdata, ,.
Translated by ChatGPT 5
京公网安备 11011102002149号