此题就是一个优先队列;
#pragma GCC optimize(2)
#include <iostream>
#include <cstring>
#include <queue>
#define maxn 20005
typedef long long ll;
using namespace std;
ll n,m,ma,fl;
struct node
{
ll pos;
ll x;
};
bool operator < (const node a,const node b)
{
if(a.x != b.x)
{
return a.x < b.x;
}
else
{
return a.pos > b.pos;
}
}
priority_queue<node>q[maxn];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
while(cin >> n)
{
memset(q,0,sizeof(q));
ll tot = 0;
for(int i = 1; i <= n ; i ++)
{
string s;
ll a,b;
cin >> s;
if(s == "IN")
{
tot++;
node k;
cin >> a >> b;
k.pos = tot;
k.x = b;
q[a].push(k);
}
if(s == "OUT")
{
cin >> a;
if(q[a].empty())
{
cout << "EMPTY" << endl;
}
else
{
node f = q[a].top();
cout << f.pos << endl;
q[a].pop();
}
}
}
}
return 0;
}