luogu1801 黑匣子

惊了呀 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+50;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 1e-8;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=0,f=1;char ch=getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch=getchar();}while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}return x*f;}

priority_queue<int> qmax;
priority_queue<int,vector<int>,greater<int> > qmin;
int a[300010];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int j=1;
    for(int i=1;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
",qmin.top());
        qmax.push(qmin.top());
        qmin.pop();
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/Kong-Ruo/p/7700634.html