#P7554. [COCI 2020/2021 #6] Index

[COCI 2020/2021 #6] Index

Description

The "H-index" measures both the number of papers a researcher has and how many citations they received. A researcher's "H-index" is the largest integer hh such that they have at least hh papers, each cited at least hh times.

Mirko has published nn papers in total, and he has qq questions: if he had published only papers from the lil_i-th to the rir_i-th, what would his "H-index" be?

Input Format

The first line contains two integers n,qn, q.

The second line contains nn integers pip_i, where pip_i is the citation count of Mirko's ii-th paper.

The next qq lines each contain two integers li,ril_i, r_i, representing a question.

Output Format

Output qq lines. Each line contains one integer, the answer to the corresponding question.

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

Hint

Constraints and Notes

This problem uses bundled testdata.

Subtask Points Constraints and Notes
11 2020 1n,q1031 \le n, q \le 10^3
22 4040 1n,q5×1041 \le n, q \le 5 \times 10^4
33 5050 No additional constraints

For 100%100\% of the testdata, 1n,q2×1051 \le n, q \le 2 \times 10^5, 1pi2×1051 \le p_i \le 2 \times 10^5, 1lirin1 \le l_i \le r_i \le n.


Explanation

The score of this problem follows the original COCI settings, with a full score of 110110.

Translated from COCI2020-2021 CONTEST #6 T5 Index

Translated by ChatGPT 5