#include<bits/stdc++.h>
using namespace std;
struct node
{
int id;
int lv;
friend bool operator < (const node x,const node y)///友源函数,重载函数
{ ///先根据等级排列,如果等级相同,则根据id排列
if(x.lv==y.lv)
{
return x.id>y.id;///id大的排前面,因为pop是从后面开始的,top()也是从队列尾部输出的
}
return x.lv<y.lv;///lv大的排后面
}
}tmp;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
tmp.id=0;///将id装入tmp中,方便,排列
priority_queue<node> q[4];///输出时候用q[i].top()
while(n--) ///queue才是q[i].front()
{
string m;
int i=0,a,b;
cin>>m;
if(m=="IN")
{
tmp.id++;
cin>>a>>b;
tmp.lv=b;
q[a].push(tmp);///队列a(1~3)排列
}
else
{
cin>>a;
if(!q[a].empty())///如果为非空就输出
{
cout<<q[a].top().id<<endl;
q[a].pop();///输出完了就删除
}else{
puts("EMPTY");
}
}
}
}
return 0;
}
priority_queue一般需要用到 friend bool operator来结构体内排序
priority_queue用.top()来输出