Codeforces Round #357 (Div. 2)C. Heap Operations
用单调队列(从小到大),模拟一下就好了,主要是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的更多相关文章
- Codeforces Round #357 (Div. 2) C. Heap Operations 模拟
C. Heap Operations 题目连接: http://www.codeforces.com/contest/681/problem/C Description Petya has recen ...
- Codeforces Round #357 (Div. 2) 优先队列+模拟
C. Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #357 (Div. 2) C
C. Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 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 ...
- 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 ...
- Codeforces Round #357 (Div. 2) B. Economy Game 水题
B. Economy Game 题目连接: http://www.codeforces.com/contest/681/problem/B Description Kolya is developin ...
- Codeforces Round #357 (Div. 2) A. A Good Contest 水题
A. A Good Contest 题目连接: http://www.codeforces.com/contest/681/problem/A Description Codeforces user' ...
- 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 ...
- Codeforces Round #357 (Div. 2) E 计算几何
传说中做cf不补题等于没做 于是第一次补...这次的cf没有做出来DE D题的描述神奇 到现在也没有看懂 于是只补了E 每次div2都是hack前2~3题 终于打出一次hack后的三题了...希望以后 ...
随机推荐
- ci中 chrome对favicon.ico请求,导致log报错 解决方法
chrome浏览器会自动对favicon.ico进行请求,所以当没有为网站添加 favicon.ico 时会出现404的页面错误在实际开发过程中,CI框架 打开 ERROR log,会一直显示ERRO ...
- 王立平--GUI与GUILayout的差别
GUI.Button (new Rect(0,0,5,5,"哈哈"); GUILayout.Button ("heheh"); 1.以上代码都是现实一个butt ...
- Java经常使用类及其经常用法
1.ArrayList java.util.ArrayList<E> add(E e) //插入尾部 add(int index, E element) remove(int index) ...
- 使用Poi对EXCLE的导入导出
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import ...
- java设计模式----真实世界的模式
设计模式的定义: 模式是在某情境下,针对某问题的某种解决方案 反模式: 告诉你如何采用一个不好的解决方案解决一个问题 要点: 1.让设计模式自然而然地出现在你的设计中,而不是为了使用而使用 2.设计模 ...
- mysql 环境变量之 group_concat_max_len
今天使用mysql group_concat()函数,对查询的数据进行字符串连接操作. 不过由于查询的结果较多,连接后的结果很长导致不能完全显示. 查询手册发现如下说明: (先说说group_conc ...
- Ajax的简单实现
Ajax的实现需要服务器端和客户端配合来实现 下面看服务器端的代码,也就是用php编写的一个后台脚本文件 <?php //设置页面内容,编码格式是utf8 header("Conten ...
- region split流程分析
region split流程分析 splitregion的发起主要通过client端调用regionserver.splitRegion或memstore.flsuh时检查并发起. Client通过r ...
- 在C++中使用Libmd5计算字符串或文件的MD5值
CppMD5Demo.cpp #include <iostream> #include <fstream> #include <chrono> #include & ...
- Windows ping源码
需要测试外网的联通性,想到了用ping.网上下载了ping的源代码,调试下整理如下: /******************************************************** ...