Just $h$-index HDU - 6278(主席树找区间大于等于k的个数)
The hh-index of an author is the largest hh where he has at least hh papers with citations not less than hh.
Bobo has published nn papers with citations a1,a2,…,ana1,a2,…,an respectively.
One day, he raises qq questions. The ii-th question is described by two integers lili and riri, asking the hh-index of Bobo if has only published papers with citations ali,ali+1,…,ariali,ali+1,…,ari.
Input
The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains two integers nn and qq.
The second line contains nn integers a1,a2,…,ana1,a2,…,an.
The ii-th of last qq lines contains two integers lili and riri.
Output
For each question, print an integer which denotes the answer.
Constraint
- 1≤n,q≤1051≤n,q≤105
- 1≤ai≤n1≤ai≤n
- 1≤li≤ri≤n1≤li≤ri≤n
- The sum of nn does not exceed 250,000250,000.
- The sum of qq does not exceed 250,000250,000.
Sample Input
5 3
1 5 3 2 1
1 3
2 4
1 5
5 1
1 2 3 4 5
1 5
Sample Output
2
2
2
3
題意:一組長度為n的序列,m次查詢。每次查詢給出兩個數字l和r。詢問的是找出最大的數字k,使得l到r之間的數字至少有k個數字大于等于k。
思路很簡單,二分答案,主席樹上求區間大于等于k的數字個數。
很多題解說的是求區間第k大,其實沒有那么麻煩,直接離散化之后二分答案k,求大于等于k的個數就行。根據個數縮短區間。
代碼如下:
努力加油a啊,(o)/~
總結
以上是生活随笔為你收集整理的Just $h$-index HDU - 6278(主席树找区间大于等于k的个数)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Sequence II HDU - 59
- 下一篇: Problem F. Grab The