跳到正文

个人记录

7.8

WYR1024约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年7月14日
更新
2026年7月14日
篇幅
约 1 分钟

版本

  1. v1当前

堆(优先队列)

快速维护序列中的最大最小值

添加删除 O(log n)

大根堆:父节点大于子节点,堆顶最大

小根堆:父节点小于子节点,堆顶最小

堆为空时,top,pop会喜提RE

C++
//大根堆
priority_pueue<int> q;//定义
q.push(100) //加入并排序
q.top(); //其余全同栈
q.pop(); 
q.size();
C++
priortiy_queue<int,vector<int>,greater<int>>p;//小根堆定义
//其余同大根堆

结构体

C++
struct P
{
    int x,y,z,t;
    bool opreator < (const P&ot) const{
        return t<ot.t;//大根堆
        //return t>ot.t 小根堆
    }
};
原文