跳到正文

算法·理论

堆

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

文章信息

发布
2024年1月5日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
int n,Q,a[100005];
priority_queue<int,vector<int>,greater<int> >q;
int main(){
	cin>>Q;
	int op,x;
	while(Q--){
		cin>>op;
		if(op==1){
			cin>>x;
			q.push(x);
		}
		if(op==2){
			cout<<q.top()<<endl;
		}
		if(op==3){
			q.pop();
		}
	}
	return 0;
}
原文