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后的三题了...希望以后 ...
随机推荐
- iOS开发之UITabBarController和UICollectionView的使用
这一篇要记录的是iOS开发中UITabBarController控件和UICollectionView控件的使用.APP跑起来之后的效果例如以下图: watermark/2/text/aHR0cDov ...
- mysql 安装与启动
1.下载mysql installer 2.安装 一直点next,直到finish. 3.安装时的配置 安装完后,选择立即开始配置. 选择standard configuration 勾选安装mysq ...
- ORACLE 8i 遇到报错:ORA-01631: max # extents (505) reached in table
近期在客户的一个8i生产库上使用statspack.发现alert中有报错: Mon Jun 16 13:17:52 2014 Errors in file /oracle/8.1.7/admin/p ...
- MySql 查询一周内记录
本周内:select * from wap_content where week(created_at) = week(now) 查询一天:select * from table where to_d ...
- 二分法和牛顿迭代实现开根号函数:OC的实现
最近有人贴出BAT的面试题,题目链接. 就是实现系统的开根号的操作,并且要求一定的误差,其实这类题就是两种方法,二分法和牛顿迭代,现在用OC的方法实现如下: 第一:二分法实现 -(double)sqr ...
- python day- 16 面向对象
1.类的相关知识 类:是指具有相同属性和技能的一类事物. 比如:人类 ,植物类,动物类,狗类. 对象:是类中的某一个实例,是类的具体表现. 比如:具体到某个人,某一个植物,某一条狗. class 是p ...
- MyCAT简单入门配置
MyCAT简单入门配置 安装jdk 建议1.7以上 安装mysql 安装MyCAT Mycat 源码:https://github.com/MyCATApache/Mycat-Server Mycat ...
- Principle of least astonishment
Principle of least astonishment - Wikipedia https://en.wikipedia.org/wiki/Principle_of_least_astonis ...
- Apache Flink 1.5.1 Released
Apache Flink: Apache Flink 1.5.1 Released http://flink.apache.org/news/2018/07/12/release-1.5.1.html ...
- 把x指针指向的4个字节次序颠倒过来
举例:x指向的内存地址,其字节内容从低到高依次分别为c1,c2,c3,c4(Delphi读取一个integer的时候,结果是c4c3c2c1,其排列规则是"高高低低"),那么结果是 ...