the kid的苹果

http://192.168.102.138/JudgeOnline/problem.php?id=2527

知识点:1.nth_element(开头,需要按顺序的位置,结尾)

    (开头结尾同sort:结尾往后开一位)

#include <bits/stdc++.h>
using namespace std;
int m;
struct edge
{
    int x;
    int y;
    int val;
}e[10010];
int a[10010];
int cnt = 0; 
int query(int x1,int y1,int x2,int y2,int k)
{
    memset(a,0,sizeof(a));
    int tot = 0;
    for(int i = 1;i <= cnt;i++)
    {
        if(e[i].x >= x1 && e[i].x <= x2 && e[i].y >= y1 && e[i].y <= y2)
            a[++tot] = -e[i].val;
    }
    nth_element(a + 1,a + k,a + tot + 1);
    return -a[k];
}
int main()
{
    scanf("%d",&m);
    int x,x1,y1,x2,y2,k;
    while(m--)
    {
        scanf("%d",&x);
        if(x == 1)
        {
            cnt++;
            scanf("%d%d%d",&e[cnt].x,&e[cnt].y,&e[cnt].val);
        }
        else 
        {
            if(x == 2)
            {
                scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&k);
                printf("%d\n",query(x1,y1,x2,y2,k));
            }
        }
    }
    return 0;
}

 

posted @ 2020-11-13 13:43  ywwywwyww  阅读(103)  评论(0编辑  收藏  举报