HDU - 6231 K-th Number

Topic links: http://acm.hdu.edu.cn/showproblem.php?pid=6231

Question is intended: to give a an array of all the sub-paragraph b k into large numbers, and seeking b m-th large numbers.

Thinking: answer binary object taken Check foot, the foot is taken equal to x is greater than a first judgment section having a large k how many. Each enumerator left point L, so that the entire section is greater than equal to the number x of k, then the number of qualifying intervals to add (NR) 
because the [r n-1,] the inner zone when the right endpoint when, to a large value k must be greater than or equal to x.

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath> 
#include<map>
#include<queue>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
int N,K;
ll M;
int a[100005];
bool check(int x)
{
    ll ans=0;
    int num=0;
    int j=1; 
    for(int= I . 1 ; I <= N; I ++ ) 
    { 
        IF (A [I]> = X) 
            NUM ++ ;
         IF (NUM == K) 
        { 
            ANS + = + N-I . 1 ; // statistics back may be formed of a total number intervals 
            the while (A [J] < X) 
            { 
                ANS + = + N-I . 1 ; // count the front section may be formed of a total number of 
                J ++ ; 
            } 
            NUM -; // reduced state 
            J ++ ; 
        } 
    } 
    IF(ans>=M)
        return true;
    else
        return false; 
} 
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%lld",&N,&K,&M);
        for(int i=1;i<=N;i++)
            scanf("%d",&a[i]);
        int l=1,r=1000000000;
        int m;
        while(l<r)
        {
            m=(l+r)/2;
            if(check(m))
                l=m+1;
            else
                r=m;
        }
        printf("%d\n",l-1);
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/2462478392Lee/p/12426164.html