poj1442(对顶堆)
#include<cstdio> #include<algorithm> #include<cstring> #include<vector> #include<queue> using namespace std; const int maxn=3000000+10; int a[maxn]; priority_queue<int,vector<int>,greater<int> >q1; priority_queue<int>q2; int main(){ int n,k; int v; scanf("%d%d",&n,&k); for (int i=1;i<=n;i++){ scanf("%d",&a[i]); } int u=0; q1.push(2000000000+100); for (int i=1;i<=k;i++){ scanf("%d",&v); for (int j=u+1;j<=v;j++){ q2.push(a[j]); } u=v; while(q2.top()>q1.top()){ q1.push(q2.top()); q2.pop(); } while(q2.size()>i){ q1.push(q2.top()); q2.pop(); } while(q2.size()<i){ q2.push(q1.top()); q1.pop(); } printf("%d\n",q2.top()); } return 0; }