bzoj4604The kth maximum number

Posted YJY_

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bzoj4604The kth maximum number相关的知识,希望对你有一定的参考价值。

暴力

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
 
#define MAXN 50010
 
int a[MAXN];
int X[MAXN],Y[MAXN],W[MAXN];
 
int C,N,Q,L;
 
int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
    while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
    return x*f;
}
 
int main()
{
    N=read(),Q=read();
    while(Q--)
    {
        int ty=read();
        if (ty==1)
            X[C]=read(),Y[C]=read(),W[C++]=read();
        else
        {
            int xl=read(),yl=read(),xr=read(),yr=read(),k=read();
            for (int i=L=0;i<C;i++)
                if (xl<=X[i] && X[i]<=xr && yl<=Y[i] && Y[i]<=yr)
                    a[L++]=W[i];
            if (k>L)
                puts("NAIVE!ORZzyz.");
            else
            {
                nth_element(a,a+(L-k),a+L);
                printf("%d\n",a[L-k]);
            }
        }
    }
    return 0;
}

  

以上是关于bzoj4604The kth maximum number的主要内容,如果未能解决你的问题,请参考以下文章

1492. The kth Factor of n

HDU 4006: The kth great number

Kth Largest in N Arrays

hdu 4006 The kth great number(优先队列)

LeetCodeMaththe kth factor of n

5403. Find the Kth Smallest Sum of a Matrix With Sorted Rows