玄学问题?
查看原帖
玄学问题?
777809
IOI_AK_TLR楼主2023/10/26 09:50
#include <bits/stdc++.h>
using namespace std;
int n;
const int N=2e5+5;
int opt,x,sta[N],top=0,ans=0,loc;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	while(n--)
	{
		cin>>opt;
		if(opt==0)
		{
			cin>>x;
			top++;
			sta[top]=x;
			if(x>ans)
				loc=top,ans=x;
		}
		else if(opt==1)
		{
			if(top==0)
				continue;
			if(loc==top)
				ans=0;
			top--;
		}
		else
		{
			if(top==0)
			{
				cout<<"0\n";
				continue;
			}
			if(ans!=0)
				cout<<ans<<'\n';
			else
			{
				for(int i=1;i<=top;i++)
					if(sta[i]>ans)
						ans=sta[i],loc=i;
				cout<<ans<<'\n';
			}
		}
	}
	return 0;
}


后4个测试点全WA,下载数据发现该程序可能会在最开始的询问里输出多余的空行,并且一开始的一些询问不能正常输出,但是开了freopen以后就没有任何问题,请问这是什么原因?

2023/10/26 09:50
加载中...