零分求助!!
查看原帖
零分求助!!
1385029
ziqikang楼主2024/11/9 19:45
#include<bits/stdc++.h>
using namespace std;

int heap[50000],top = 0,n;
struct s{
	int op;
	int x;
}c[1000010];

void push(int x)
{
	top++;
	int p = top;
	while (p > 1) {
		if (heap[p/2] < x) {
			break;
		}
		heap[p] = heap[p/2];
		p = p / 2;
	}
	heap[p] = x;
}

int pop() {
	heap[0] = heap[1];
	int x = heap[top];
	top--;
	int fa = 1;
	while (fa*2 <= top) {
		int son = fa*2;
		if (heap[son+1] < heap[son]) son++;
		if (heap[son] > x) break;
		heap[fa] = heap[son];
		fa = son;
	}
	heap[fa] = x;
	return heap[0];
} 
void dlt() {
	int x = heap[top];
	int fa = 1;
	while (fa*2 <= top) {
		int son = fa*2;
		if (heap[son+1] < heap[son]) son++;
		if (heap[son] > x) break;
		heap[fa] = heap[son];
		fa = son;
	}
}
int main()
{
	cin >> n;
	for (int i = 1;i <= n;i++) {
		cin >> c[i].op;
		if (c[i].op == 1) {
			cin >> c[i].x;
		}
	}
	for (int i = 1;i <= n;i++) {
		if (c[i].op == 1) {
			push(c[i].x);
		}
		else if (c[i].op == 3) {
			dlt();
		}
		else if (c[i].op == 2) {
			cout << pop() << endl;
		}
	}
	return 0;
}
2024/11/9 19:45
加载中...