hdu1873优先队列

时间:2024-01-13 21:54:02
 #include<stdio.h>
#include<queue>
using namespace std;
struct node
{
int id;
int val;
friend bool operator< (node a,node b)
{
if(a.val!=b.val)
return a.val<b.val;
else
{
return a.id>b.id;
}
}
};
int n;
int main()
{
int i,j;
char s[];
int num,set;
while(scanf("%d",&n)!=EOF)
{
num=;
node temp;
priority_queue<node>q[];
for(i=;i<=n;i++)
{
scanf("%s",s);
if(s[]=='I')
{
scanf("%d %d",&set,&temp.val);
temp.id=num++;
q[set].push(temp);
}
else
{
scanf("%d",&set);
if(q[set].empty())
{
printf("EMPTY\n");
continue;
}
node exm=q[set].top();
q[set].pop();
printf("%d\n",exm.id);
}
}
}
}