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后的三题了...希望以后 ...
随机推荐
- 用df命令显示磁盘使用量和占用率。
使用“df -k”命令,以k为单位显示磁盘使用量和占用率. root@gsg43:/tmp# df -kFilesystem 1K-blocks Used Available Use% ...
- leetcode Valid Palindrome C++&python 题解
题目描写叙述 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...
- VirtualBox中使用双网卡实现CentOS既能上网(校园网)也能使用SSHclient
近期在虚拟机中使用linux操作系统,之前使用NAT方式上网,能够畅通无阻.可是使用SSHclient连接linux虚拟机就必须为其指定固定的IP地址.依照网上的配置方法使用桥接方式,这种方式是能够的 ...
- Arrays.asList基本用法
目录 说明 基本用法 陷阱 改观 说明 asList 是 java.util.Arrays 类的一个方法 public static <T> List<T> asList(T. ...
- python的pexpect模块
Pexpect 是 Don Libes 的 Expect 语言的一个 Python 实现,是一个用来启动子程序,并使用正则表达式对程序输出做出特定响应,以此实现与其自动交互的 Python 模块. P ...
- GTK入门学习:布局容器之水平布局
假设我们希望窗体里多放加入几个控件,直接加入是不成功的.由于窗体仅仅能容纳一个控件的容器. 这时候.我们须要借助布局容器,我们先把布局容器加入到窗体里.然后再把所须要加入的控件放在布局容器里. 布局容 ...
- HDU 6068 Classic Quotation KMP+DP
Classic Quotation Problem Description When online chatting, we can save what somebody said to form h ...
- C++中的const完全解析
1. const修饰普通变量和指针 const修饰变量,一般有两种写法:const TYPE value;TYPE const value; 这两种写法在本质上是一样的.它的含义是:const修饰的类 ...
- 使用delphi 开发多层应用(十六)使用XMLRPC 实现basic4android 远程调用RTC服务(讲述了RTC的特点,其底层通讯协议是自己封装SOCK 库,与kbmmw 的适合场合不完全一样)
RealThinClient (以下简称RTC) 也是一款delphi 多层开发的框架,由于其底层通讯协议是自己封装SOCK 库,抛弃了 大家诟病的indy,因此表现的非常稳定,效率也非常高, ...
- python二维数组初始化
>>> a=[[0]*3 for i in range(3)]>>> a[[0, 0, 0], [0, 0, 0], [0, 0, 0]]>>> ...