HIHO1105
又是一道水题
堆分为大根堆和小根堆,而其中的对堆的操作有存和取,“取”操作是取堆中最大(最小)的元素,在STL中priority_queue中实现了这两个功能,就有了如下代码:
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
#define lson rt<<1
#define rson rt<<1 | 1
#define Mid ( (L+R) >> 1 )
#define debug(x) cout<<#x<<":"<<(x)<<endl;
#define Pause system("pause");
#define RF freopen("1.txt", "r", stdin);
#define WF freopen("11.txt", "w", stdout);
#define QCIN ios::sync_with_stdio(false);
int dir[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
int main()
{
// RF
int n, y;
char x;
cin >> n;
priority_queue<int> pq;
for(int i=0; i<n; ++i) {
cin >> x;
if( x == 'A' ) {
cin >> y;
pq.push(y);
}else {
printf("%d\n", pq.top());
pq.pop();
}
}
return 0;
}