首页 > 代码库 > STL 堆

STL 堆

洛谷P3378 【模板】堆

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;typedef long long ll;const int N=1e6+5;inline int read(){    char c=getchar();int x=0,f=1;    while(c<0||c>9){if(c==-)f=-1;c=getchar();}    while(c>=0&&c<=9){x=x*10+c-0;c=getchar();}    return x*f;}int n,op,x;int a[N],len=0;inline bool cmp(int a,int b){return a>b;}int main(){    n=read();    for(int i=1;i<=n;i++){        op=read();        if(op==1){            a[len++]=read();            push_heap(a,a+len,cmp);        }else if(op==2) printf("%d\n",a[0]);        else pop_heap(a,a+len,cmp),len--;    }}

 

STL 堆