【bzoj4604】The 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;
}

  

时间: 2024-10-13 10:34:41

【bzoj4604】The kth maximum number的相关文章

【42】414. Third Maximum Number

414. Third Maximum Number Description Submission Solutions Add to List Total Accepted: 20624 Total Submissions: 76932 Difficulty: Easy Contributors: ZengRed, 1337c0d3r Given a non-empty array of integers, return the third maximum number in this array

【LeetCode】Binary Tree Maximum Path Sum 解题报告

[题目] Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example: Given the below binary tree, 1 / 2 3 Return 6. [解析] 题意:在二叉树中找一条路径,使得该路径的和最大.该路径可以从二叉树任何结点开始,也可以到任何结点结束. 思路:递归求一条经过root的最大路径,这条路径可能是:

【POJ】2104 K-th Number

区间第K大数.主席树可解. 1 /* 2104 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include <stack> 9 #include <vector> 10 #include <deque>

[bzoj4604] The kth maximum number

暴力可过... 重新看了下快速选择.. 1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<algorithm> 5 #include<cstdlib> 6 using namespace std; 7 const int maxn=50233; 8 struct zs{int x,y,num;}b[maxn]; 9 int a[maxn]; 10 int

【LeetCode】Excel Sheet Column Number

题意: Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 思路: 其实就是个进制转换.水水就过.倒是 Python 的代码让我

【leetcode】Binary Tree Maximum Path Sum (medium)

Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. 找树的最大路径和 注意路径可以从任意点起始和结束. 我发现我真的还挺擅长树的题目的,递归不难.就是因为有个需要比较的量(最大和),所以需要再写一个函数. 因为路径可以从任意点起始和结束,所以每次递归的时候左右子树小于等于0的就可以不管了. #include <iostream> #include

【LeetCode】215. Kth Largest Element in an Array

题目: Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example,Given [3,2,1,5,6,4] and k = 2, return 5. Note: You may assume k is always valid, 1 ≤ k ≤ arr

【C++】Calculate the exact number of e.

As we know,the Natural Constant,which usually called e,has two main ways of expressing: 1. \( \lim_{n \to \infty}\sum_{i=0}^{n}(\frac{1}{i!}) \) 2. \( \lim_{n \to \infty}(1+\frac{1}{n})^{n} \) Let we have a try,the following two python(Version 3.4) p

【leetcode】Binary Tree Maximum Path Sum

Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example:Given the below binary tree, 1 / 2 3 Return 6. 用递归确定每一个节点作为root时,从root出发的最长的路径 在每一次递归中计算maxPath 1 /** 2 * Def