其他分享
首页 > 其他分享> > 堆(模板)(优先队列实现)

堆(模板)(优先队列实现)

作者:互联网

P3378

#include <bits/stdc++.h>
using namespace std;
priority_queue<int, vector<int>, greater<int>> q;
int n;
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        int choice;
        scanf("%d", &choice);
        if (choice == 1)
        {
            int t;
            scanf("%d", &t);
            q.push(t);
        }
        else if (choice == 2)
        {
            printf("%d\n", q.top());
        }
        else
        {
            q.pop();
        }
    }
}

 

标签:priority,优先,greater,队列,queue,int,模板
来源: https://www.cnblogs.com/Wang-Xianyi/p/16536300.html