MSE07B - Double Queue
Tác giả: happyboy99x
Ngôn ngữ: C++
#include<cstdio>
#include<set>
using namespace std;
typedef pair<int, int> ii;
set<ii> memo;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
for(int ctrl; scanf("%d",&ctrl) != EOF && ctrl != 0;) {
if(ctrl == 1) {
int k, p; scanf("%d%d",&k,&p);
memo.insert(ii(p, k));
} else if(memo.empty()) printf("0\n");
else if(ctrl == 2) {
printf("%d\n", memo.rbegin()->second);
set<ii>::iterator it = memo.end();
memo.erase(--it);
} else {
printf("%d\n", memo.begin()->second);
memo.erase(memo.begin());
}
}
}