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. bootstrap学习总结

    bootstrap网站下载: 谷歌浏览器访问:http://github.com/twbs/bootstrap/    右上角(clone or download) 编译版bootstrap:http ...

  2. nat 共享上网软件

    http://www.nat32.com/ SinforNat WinGate

  3. C# GDI+绘图 z

    一.坐标系 坐标系是图形设计的基础.GDI+使用三个坐标空间:世界.页面和设备,其中,世界坐标是用于建立特殊图形世界模型的坐标系,也是在.NET Framework中传递给方法的坐标系.而页面坐标系是 ...

  4. gitbook build 报错

    如下图所示 解决方案,通过 everythings 找到 copyPluginAssets.js,然后搜索 confirm,将其值  true –> false 参考链接:https://git ...

  5. Android ListView滚动到指定的位置

    这篇文章主要给大家介绍了Android中的ListView如何滚动到指定的位置,文章给出了两种解决的方法,并给出详细的示例代码,相信会对大家的理解和学习很有帮助,有需要的朋友们下面来一起看看吧. 本文 ...

  6. 【ASP.NET Core】浅说目录浏览

    何谓“浅说”?就是一句话说不完,顶多两句话就介绍完毕,然后直接给上实例的解说方式.化繁为简,从七千年前到现在,从老祖宗到咱们,一直都在追求的理想目标,尽可能把复杂的东西变成简单的. 老周告诉你一个可以 ...

  7. Linux命令行烧录树莓派镜像至SD卡

    首先下载镜像压缩包 验证压缩包的未被串改 1 sha1sum 2013-09-25-wheezy-raspbian.zip 对此命令的输出结果和官网给出的SHA-1 Checksum进行比对,如果一致 ...

  8. mingw 构建 gdal 2.1.2

    目录 1.准备 2.生成Makefile 3.编译 4.编译遇到错误及解决办法 1.生成静态库时候ar提示参数列表太长 2.生成动态库时候g++提示参数列表太长 前两日有人在oschian上问我min ...

  9. 微信小程序tab切换,可滑动切换,导航栏跟随滚动实现

    简介 看到今日头条小程序页面可以滑动切换,而且tab导航条也会跟着滚动,点击tab导航,页面滑动,切导航栏也会跟着滚动,就想着要怎么实现这个功能 像商城类商品类目如果做成左右滑动切换类目用户体验应该会 ...

  10. [druid]大数据挑战——如何使用Druid实现数据聚合

    -- 知道你为什么惧组件很多的一些开源软件? 因为缺乏阅读能力. 最近我接手了druid+kafka+elk一套等日志系统. 但是我对druid很陌生, 周旋了几天, 官网文档快速开始照着做了下. 看 ...