当前位置: 代码迷 >> 综合 >> POJ - 1442 Black Box(二叉堆)
  详细解决方案

POJ - 1442 Black Box(二叉堆)

热度:107   发布时间:2023-11-25 07:27:15.0

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;
}