#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
string s1 = "insert";
string s2 = "getMin";
string s3 = "removeMin";
priority_queue<int,vector < int > , greater < int > > q;
struct node{
int k,v;
}a[1000010];
int main()
{
int n;
int ans=0;
scanf("%d",&n);
while(n--){
string s;int v;
cin>>s;
if(s==s3){
if(q.empty()){
ans++;a[ans].k=1;a[ans].v=1;
}
else q.pop();
ans++;a[ans].k=3;
}
else{
cin>>v;
if(s==s1){q.push(v);ans++;a[ans].k=1;a[ans].v=v;}
else{
while(!q.empty()){
if(q.top()<v){
q.pop();ans++;a[ans].k=3;
}
else break;
}
if(q.empty()||q.top()>v){
q.push(v);ans++;a[ans].k=1,a[ans].v=v;
}
ans++;a[ans].k=2,a[ans].v=v;
}
}
}
printf("%d\n",ans);
for(int i=1;i<=ans;i++){
if(a[i].k==3) printf("removeMin\n");
if(a[i].k==2) printf("getMin %d\n",a[i].v);
if(a[i].k==1) printf("insert %d\n",a[i].v);
}
return 0;
}
CF681C 模拟
最新推荐文章于 2022-05-29 20:01:10 发布