P1801 black box

Questions surface: https://www.luogu.org/problemnew/show/P1801

The present problem is to have the first element into a large heap root, then when the elements in the heap large root of k greater than or equal, put into a small excess root element stack, thus ensuring that the top rootlets piles are smaller then when the output k End after a small number of k, then put it back in the large root heap (as k increases)

Code:

#include<iostream>
#include<cstdio> #include<queue> using namespace std; int a[200005],g[200005]; priority_queue<int> B; priority_queue<int,vector<int>,greater<int> > A; int main(){ int n,m,k=1; scanf("%d%d",&n,&m); for(int x=1;x<=n;x++){ scanf("%d",&a[x]); } for(int x=1;x<=m;x++){ scanf("%d",&g[x]); } for(int j=1;j<=n;j++){ B.push(a[j]); if(B.size()>=k){ A.push(B.top()); B.pop(); } while(j==g[k]){ printf("%d\n",A.top()); B.push(A.top()); A.pop(); k++; } } return 0; }

Guess you like

Origin www.cnblogs.com/ukcxrtjr/p/11119967.html