用单调队列(从小到大),模拟一下就好了,主要是getMin比较麻烦,算了,都是模拟。。。。也没什么好说的。。

#include<cstdio>
#include<map>
#include<queue>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std; priority_queue<int, vector<int>, greater<int> >qq; struct asd{
char s[10];
int k;
};
asd q[500000]; int main()
{
int n;
scanf("%d",&n);
int x;
char ss[10];
int num=0;
for(int i=0;i<n;i++)
{
scanf("%s",&ss); if(ss[0]=='i')
{
scanf("%d",&x);
strcpy(q[num].s,"insert");
q[num].k=x;
num++;
qq.push(x);
}
else if(ss[0]=='r')
{
int s1,s2;
if(!qq.empty())
{
s1=qq.top();
strcpy(q[num].s,"removeMin");
q[num].k=s1;
num++;
qq.pop();
}
else
{
strcpy(q[num].s,"insert");
q[num].k=0;
num++; strcpy(q[num].s,"removeMin");
q[num].k=0;
num++;
}
}
else if(ss[0]=='g')
{
scanf("%d",&x);
int s1;
if(!qq.empty())
{
s1=qq.top();
if(s1==x)
{
strcpy(q[num].s,"getMin");
q[num].k=x;
num++;
}
else if(s1>x)
{
strcpy(q[num].s,"insert");
q[num].k=x;
num++;
qq.push(x); strcpy(q[num].s,"getMin");
q[num].k=x;
num++;
}
else if(s1<x)
{
int flag=0;
while(!qq.empty())
{
int nn=qq.top();
if(nn==x)
{
strcpy(q[num].s,"getMin");
q[num].k=x;
num++;
break;
}
else if(nn>x)
{
strcpy(q[num].s,"insert");
q[num].k=x;
num++;
qq.push(x); strcpy(q[num].s,"getMin");
q[num].k=x;
flag=1;
num++;
break;
}
else if(nn<x)
{
strcpy(q[num].s,"removeMin");
q[num].k=nn;
num++;
qq.pop();
}
}
}
}
if(qq.empty())
{
strcpy(q[num].s,"insert");
q[num].k=x;
num++;
qq.push(x); strcpy(q[num].s,"getMin");
q[num].k=x;
num++;
}
}
}
printf("%d\n",num);
for(int i=0;i<num;i++)
{
if(q[i].s[0]=='r')
{
printf("%s\n",q[i].s);
}
else
{
printf("%s %d\n",q[i].s,q[i].k);
}
}
return 0;
} /*
2
insert
getMin 4 8
insert 1
insert 1
insert 1
removeMin
removeMin
removeMin
getMin 2
getMin 3
13
insert -851839419
removeMin
removeMin
g /*
2
insert
getMin 4 8
insert 1
insert 1
insert 1
removeMin
removeMin
removeMin
getMin 2
getMin 3
13
insert -851839419
removeMin
removeMin
getMin -624068418
insert 119194510
removeMin
removeMin
removeMin
getMin -179673992
getMin 520596304
insert -265233646
getMin -222234500
removeMin 6
insert 1
insert 1
insert 1
removeMin
getMin 6
getMin 3 4
getMin 4
getMin 3
getMin 2
getMin 1 4
getMin 1
getMin 2
getMin 3
getMin 4 */

Codeforces Round #357 (Div. 2)C. Heap Operations的更多相关文章

  1. Codeforces Round #357 (Div. 2) C. Heap Operations 模拟

    C. Heap Operations 题目连接: http://www.codeforces.com/contest/681/problem/C Description Petya has recen ...

  2. Codeforces Round #357 (Div. 2) 优先队列+模拟

    C. Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  3. Codeforces Round #357 (Div. 2) C

    C. Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  4. Codeforces Round #357 (Div. 2) E. Runaway to a Shadow 计算几何

    E. Runaway to a Shadow 题目连接: http://www.codeforces.com/contest/681/problem/E Description Dima is liv ...

  5. Codeforces Round #357 (Div. 2) D. Gifts by the List 水题

    D. Gifts by the List 题目连接: http://www.codeforces.com/contest/681/problem/D Description Sasha lives i ...

  6. Codeforces Round #357 (Div. 2) B. Economy Game 水题

    B. Economy Game 题目连接: http://www.codeforces.com/contest/681/problem/B Description Kolya is developin ...

  7. Codeforces Round #357 (Div. 2) A. A Good Contest 水题

    A. A Good Contest 题目连接: http://www.codeforces.com/contest/681/problem/A Description Codeforces user' ...

  8. Codeforces Round #357 (Div. 2) A

    A. A Good Contest time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  9. Codeforces Round #357 (Div. 2) E 计算几何

    传说中做cf不补题等于没做 于是第一次补...这次的cf没有做出来DE D题的描述神奇 到现在也没有看懂 于是只补了E 每次div2都是hack前2~3题 终于打出一次hack后的三题了...希望以后 ...

随机推荐

  1. Android studio 导入githubproject

    Blog From:http://blog.csdn.net/onlysnail/article/details/45115093 从github下载两个开源项目: PagerSlidingTabSt ...

  2. UP Board USB无线网卡选购指南

    前言 原创文章,转载引用务必注明链接,水平有限,欢迎指正. 本文环境:ubilinux 3.0 kernel 4.4.0 本文使用Markdown写成,为获得更好的阅读体验和正常的图片.链接,请访问我 ...

  3. lua 获取当前执行目录 lfs 库

    lua lfs 库 lfs.attributes(filepath [, aname]) 获取路径指定属性 lfs.chdir(path) 改变当前工作目录,成功返回true,失败返回nil加上错误信 ...

  4. SpringMVC框架下使用jfreechart绘制折线图,柱状图,饼状图

    java代码 @Controller public class CityAction { @Autowired private CityBiz cityBiz; //柱状图 @RequestMappi ...

  5. 【Android】Android聊天机器人实现

    昨天看到一个Android视频教程讲图灵机器人.那个API接口用起来还是挺方便的,就准备自己动手做一个了. 另外自己还使用了高德地图的API接口用于定位(曾经用过高德的接口,比X度方便) 大体流程: ...

  6. Java虚拟机平台无关性

    jruby Java 虚拟机面试题全面解析(干货) - Yano_nankai的博客 - CSDN博客 http://m.blog.csdn.net/Yano_nankai/article/detai ...

  7. Does Hadoop require SSH?

    https://wiki.apache.org/hadoop/FAQ#Does_Hadoop_require_SSH.3F Hadoop provided scripts (e.g., start-m ...

  8. android studio Error:Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request"

    android studio运行会遇到Error:Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Reques ...

  9. MRP-MD04 中的函数

    1.需求溯源 : MD_PEGGING_NODIALOG 2.实时库存 : MD_STOCK_REQUIREMENTS_LIST_API 这个函数中MDPSX 和 MDEZX 是通过 MDPS 的 I ...

  10. elastica安装

    https://www.elastic.co/guide/en/elasticsearch/reference/current/zip-targz.html