题意:
维护一个集合,操作有1:加入一个元素,2:删除最大元素,3:删除最小元素。
分析:
map本质是个容器,且具有第一个关键字有序的性质,所以用它来水水就好啦~
代码:
//poj 3481
//sep9
#include <iostream>
#include <map>
using namespace std;
map<int,int> mymap;
map<int,int>::iterator iter;
int main()
{
int x,sum=0;
while(scanf("%d",&x)==1&&x){
if(x==1){
int a,b;
scanf("%d%d",&a,&b);
mymap[b]=a;
++sum;
}else if(x==2){
if(sum==0)
printf("0\n");
else{
iter=mymap.end();
--iter;
printf("%d\n",iter->second);
mymap.erase(iter);
--sum;
}
}else if(x==3){
if(sum==0)
printf("0\n");
else{
iter=mymap.begin();
printf("%d\n",iter->second);
mymap.erase(iter);
--sum;
}
}
}
return 0;
}