#P1533. 可怜的狗狗

可怜的狗狗

Description

Xiao Ka has nn dogs. Because of different breeds and ages, each dog has a different beauty value. The beauty value is inversely related to how pretty a dog is (the lower the beauty value, the prettier). At mealtime, the dogs stand in a line in order, waiting for their owner to give them food.

But Jiajia is really lazy; he refuses to feed so many dogs. Each time, he only feeds the dog that is the kk-th most beautiful among the ii-th to the jj-th dogs (how heartless!). Moreover, to ensure that no single dog is fed too many times, none of the intervals [i,j][i, j] contains another.

Input Format

The first line contains two integers n,mn,m, where mm is the number of times Jiajia feeds the dogs.

The second line contains nn integers, where the ii-th dog's beauty value is aia_i.

The next mm lines each contain 33 integers i,j,ki,j,k, asking for the beauty value of the dog that is the kk-th most beautiful among the dogs from ii to jj.

Output Format

mm lines, each containing one integer, which is the beauty value of the dog fed each time.

7 2
1 5 2 6 3 7 4
1 5 3
2 7 1

3
2

Hint

Constraints: $1\le n \le 3\times 10^5 ,1\le m \le5\times10^4,0\le a_i<2^{31}$,且 aia_i 互不相同。

Translated by ChatGPT 5