49分TLE求助!
查看原帖
49分TLE求助!
704634
poor_OIer楼主2023/3/19 21:37

49分评测结果

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,x,a;
ll sta[200005],top;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(a==0)
		{
			cin>>x;
			sta[++top]=x;
		}
		if(a==1)
			top--;
		if(a==2)
		{
			if(top==0)
			{
				cout<<0;
				continue;
			}
			int maxx=-1;
			for(int j=1;j<=top;j++)
				if(sta[j]>maxx)
					maxx=sta[j];
			cout<<maxx<<endl;
		}
	}
	return 0;
}

求优化

2023/3/19 21:37
加载中...