POJ - 1442 Black Box(二叉堆)
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
const int N = 30010;
int a[N],b[N];
int main()
{
int n,m;scanf("%d%d",&n,&m);for(int i=1;i<=n;i++) scanf("%d",&a[i]);for(int i=1;i<=m;i++) scanf("%d",&b[i]); priority_queue<int> down;priority_queue<int,vector<int>,greater<int> > up;for(int i=1,j=1;i<=m;i++){
while(j<=b[i]){
if(down.empty()||a[j]>=down.top()) up.push(a[j]);else{
up.push(down.top());down.pop();down.push(a[j]);}j++;}down.push(up.top());up.pop();printf("%d\n",down.top());}return 0;
}