Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao what the kth great number is. Because the number written by Xiao Ming is too much, Xiao Bao is feeling giddy. Now, try to help Xiao Bao.

Input

There are several test cases. For each test case, the first line of input contains two positive integer n, k. Then n lines follow. If Xiao Ming choose to write down a number, there will be an " I" followed by a number that Xiao Ming will write down. If Xiao Ming choose to ask Xiao Bao, there will be a "Q", then you need to output the kth great number.

Output

The output consists of one integer representing the largest number of islands that all lie on one line.

Sample Input

8 3

I 1

I 2

I 3

Q

I 5

Q

I 4

Q

Sample Output

1

2

3

Hint

Xiao Ming won't ask Xiao Bao the kth great number when the number of the written number is smaller than k. (1=<k<=n<=1000000).

输出第k大的数字,优先队列水题

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define scf(x) scanf("%d",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define prf(x) printf("%d\n",x)
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
using namespace std;
const double pi=acos(-1.0);
const int N=3e2+10;
priority_queue<int> q1;
priority_queue<int,vector<int>,greater<int> > q2;
void del()
{
while(!q2.empty())
q2.pop();
}
int main()
{
int n,x,k;
char c;
while(~scff(n,k))
{
del();
while(n--)
{
getchar();
sf("%c",&c);
if(c=='I')
{
scf(x);
q2.push(x);
if(q2.size()>k)
q2.pop();
}else
prf(q2.top());
}
}
return 0;
}

C - The kth great number 优先队列的更多相关文章

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

    /********************************************************** 题目: The kth great number(HDU 4006) 链接: h ...

  2. HDU 4006 The kth great number 优先队列、平衡树模板题(SBT)

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006 题目大意: 第一行 输入 n k,后有 n 行,对于每一行有两种状态 ,①“I x” : 插入 ...

  4. hdoj 4006 The kth great number【优先队列】

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

  5. The kth great number(优先队列)

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

  6. HDU 4006 The kth great number (优先队列)

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

  7. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  8. HDOJ4006 The kth great number 【串的更改和维护】

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

  9. [LeetCode] Kth Smallest Number in Multiplication Table 乘法表中的第K小的数字

    Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number ...

随机推荐

  1. IPAddress.Any 解决本地ip和服务器ip切换问题

    IPAddress.Any表示本机ip,换言之,如果服务器绑定此地址,则表示侦听本机所有ip对应的那个端口(本机可能有多个ip或只有一个ip)IPAddress.Any微软给出的解释是:Provide ...

  2. android:如何通过chrome远程调试APP中的webView的h5代码

    今天出现一个问题,在老板的Mate9 Pro上,我们APP的所有H5页面都是一片空白,但是在其他手机上都是好的,那么我们就怀疑是h5报错了,但是到底是什么错,无法得知,所以就想要可以像在pc的chro ...

  3. 编写支持SSR的通用组件指南

    原文来自:https://blog.lichter.io/posts/the-guide-to-write-universal-ssr-ready-vue-compon? utmcampaign=Vu ...

  4. jquery的deferred使用详解

    原文:hhtps://www.cnblogs.com/shijingjing07/p/6403450.html -------------------------------------------- ...

  5. alibaba的springcloud孵化器项目

    Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案.此项目包含开发分布式应用微服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开发分布式 ...

  6. RSEG用法和汇编问号的涵义

    RSEG是段选择指令,要想明白它的意思就要了解段的意思.段是程序代码或数据对象的存储单位.程序代码放到代码段,数据对象放到数据段.段分两种,一是绝对段,一是再定位段.绝对段在汇编语言中指定,在用L51 ...

  7. SQL DML 数据操纵语句

    前言 DML(Data Manipulation Language)语句:数据操纵语句,用于添加.删除.更新和查询数据库记录,并检查数据完整性.常用的语句关键字主要包括 insert.delete.u ...

  8. Git忽略规则.gitignore忽略node_modules文件夹

    在项目文件夹里添加.gitignore的文件 打开文件,在里面添加 /node_modules

  9. 【转】使用minizip解压缩多个文件(基于zlib)

    原帖子:使用minizip解压缩多个文件(基于zlib) 写作目的:之前在网上看到很多人在寻找可以解压缩多个文件的程序,其中有尝试zlib的,使用zlib的源码可以生成后缀为点gz的压缩文件,但是一次 ...

  10. go mod代理和小技巧

    代理 go mod的代理比较出名的有微软的athens,可以基于它搭建一个私有的代理,管理内部的私有代码,而且微软提供了一个公共的代理,我们可以直接使用 Linux export GOPROXY=&q ...