如果直接写换行,你将得到满屏幕的wa~~
查看原帖
如果直接写换行,你将得到满屏幕的wa~~
1168588
FASTergood楼主2024/6/12 20:36

#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1000010;
int h[N], cnt;
int n, m,ans;
void down(int u)
{
	int t = u;
	if (u * 2 <= cnt && h[u * 2] < h[t])t = u * 2;
	if (u * 2 + 1 <= cnt && h[u * 2 + 1] < h[t])t = u * 2 + 1;
	if (u != t)
	{
		swap(h[t], h[u]);
		down(t);
	}
}
void up(int u)
{
	while (u / 2 && h[u / 2] > h[u])
	{
		swap(h[u / 2], h[u]);
		u /= 2;
	}
}
int main()
{
	cin.tie(0);cout.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> n;
	while (n--)
	{
		int w,x;
		cin >> w;
		if (w == 1)
		{
			cin >> x;
			h[++cnt] = x;
			
			up(cnt);
		}
		else if (w == 2)
		{
			cout << h[1];
			puts("");//如果直接写换行,
			//你将得到满屏幕的wa~~为什么??????
		}
		else if (w == 3)
		{

			h[1] = h[cnt--];
			down(1);
		}
	}


}
2024/6/12 20:36
加载中...