#P3730. 曼哈顿交易

    ID: 2694 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>莫队洛谷原创块状链表,块状数组,分块

曼哈顿交易

Description

  • NN 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 kk-th smallest popularity?

Input Format

  • The first line contains two positive integers N,MN,M, representing the number of people and the number of queries.
  • The next line contains NN positive integers, where aia_i is the stock held by the ii-th person.
  • The next MM lines each contain three positive integers l,r,kl,r,k, representing a query asking for the kk-th smallest popularity in the interval [l,r][l, r]. It is guaranteed that lrl\leq r.

Output Format

  • For each query, output one integer on a separate line, which is the kk-th smallest popularity value in the interval [l,r][l, r].
  • If kk is greater than the number of distinct stocks in the interval, output 1-1.
4 4  
2 3 3 3  
1 4 1  
1 4 2  
1 3 2
1 3 3
1  
3  
2  
-1

Hint

For 20%20\% of the testdata, N,M1000N,M\leq 1000.

For another 10%10\% of the testdata, all queries have l=1,r=Nl=1, r=N.

For 100%100\% of the testdata, 1N,M1051\leq N, M\leq 10^51ai1091\leq a_i\leq 10^9.

Translated by ChatGPT 5