#P2310. loidc,看看海

loidc,看看海

Description

loidc plans to take the LOI team members to the seaside to have fun after the exam. So he wants to write a program to let them understand the wave conditions over a period of time.

His command is entered like this:

x y k\texttt{x y k}

This asks, within time [x,y][x, y], for the unit time index at which the kk-th smallest wave height occurs.

But when he was just about to open Dev-pas++, loidc found that his computer was broken. Being lazy as always, he asks you for help. He hopes you can finish the program within 11 second.

Of course, loidc will tell you the wave height for all time indices in advance, so rest assured. As for how he obtained them, that is unknown.

Input Format

  • The first line contains an integer nn, the total number of time indices.
  • The second line contains nn numbers aia_i, in order, representing the wave height at each of the nn unit time indices. It is guaranteed that all time indices have pairwise distinct wave heights.
  • The third line contains an integer mm, the number of queries.
  • The next mm lines each contain 33 integers x,y,kx, y, k, representing one query.

Output Format

Output mm lines, each being the answer to one query.

5
1 2 3 4 5
3
2 4 2
1 5 1
3 3 1

3
1
3

Hint

  • For 30%30\% of the testdata, n,m200n, m \le 200.
  • Constraints: For 100%100\% of the testdata, 1n,m40001 \le n, m \le 4000, 1ai1051 \le a_i \le 10^5 and aia_i are pairwise distinct, 1xyn1 \le x \le y \le n, 1kyx+11 \le k \le y - x + 1.

Translated by ChatGPT 5