heap

最小优先:priority_queue,greater >Q_minfirst;
最大优先:priority_queue,less >Q_maxfirst;

题目链接:小根堆

template
struct heap
{
    T hp[1000005];
    int idx;
    heap():idx(0)
    {
        memset(hp,0,sizeof(hp));
    }
    void push(T x)
    {
        hp[++idx]=x;
        int t=idx;
        while(t!=1 && hp[t]>1])
            swap(hp[t>>1],hp[t]),t>>=1;
    }
    void pop(void)
    {
        hp[1]=hp[idx--];
        int t=1,y=1;
        while(1)
        {
            if((t<<1)<=idx && hp[t<<1]

你可能感兴趣的:(heap)