求调!第11个点RE了!
查看原帖
求调!第11个点RE了!
979972
qinshiv楼主2024/1/29 09:03
#include<bits/stdc++.h>
using namespace std;
int heap[100005];
int heap_size=0;
void put(int d)
{
	int now,next;
	heap[++heap_size]=d;
	now=heap_size;
	while(now>1)
	{
		next=now>>1;
		if(heap[now]>=heap[next])break;
		swap(heap[now],heap[next]);
		now=next;
	}
}
int get()
{
	int now=1,next,res=heap[1];
	heap[1]=heap[heap_size--];
	while(now*2<=heap_size)
	{
		next=now*2;
		if(next<heap_size&&heap[next+1]<heap[next])next++;
		if(heap[now]<=heap[next])break;
		swap(heap[now],heap[next]);
		now=next;
	}
	return res;
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int k;
		cin>>k;
		if(k==1)
		{
			int p;
			cin>>p;
			put(p);
		}
		if(k==2)
		{
			cout<<heap[1]<<endl;
		}
		if(k==3)
		{
			get();
		}
	}
	return 0;
}
2024/1/29 09:03
加载中...