惊了呀 Splay Treap
这都什么玩意
两个优先队列搞定
#include <bits/stdc++.h>
using namespace std;
#define LL long long
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f;
const int N =1e3+;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 1e-;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-; ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;}priority_queue<int> qmax;
priority_queue<int,vector<int>,greater<int> > qmin;
int a[];
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
int j=;
for(int i=;i<=m;i++){
int x;
scanf("%d",&x);
for(;j<=x;j++)
if(!qmax.empty()&&a[j]<qmax.top()){
qmin.push(qmax.top());
qmax.pop();
qmax.push(a[j]);
}
else qmin.push(a[j]);
printf("%d\n",qmin.top());
qmax.push(qmin.top());
qmin.pop();
}
return ;
}