灵异事件
  • 板块P1165 日志分析
  • 楼主xhz0311
  • 当前回复22
  • 已保存回复22
  • 发布时间2023/3/12 12:30
  • 上次更新2023/10/23 21:47:15
查看原帖
灵异事件
747883
xhz0311楼主2023/3/12 12:30

除了样例,其他的点都过了

? ? ? (此时状态)

手打栈。

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int N,k;
	cin>>N;
	int a[N+1],maxn[N+1],top=0,topmax=0;
	for (int i=1; i<=N; i++)
	{
		cin>>k;
		if (k==0)
		{
			int p;
			cin>>p;
			a[++top]=p;
			if (p>maxn[topmax])
			{
			    maxn[++topmax]=p;
			}
		}
		else if (k==1)
		{
			if (top!=0)
			{
			    if (maxn[topmax]==a[top])
			    {
			        topmax--;
			    }
				top--;
			}
		}
		else
		{
			if (top==0)
			{
				cout<<"0"<<endl;
			}
			else
			{
    			cout<<maxn[topmax]<<endl;
			}
		}
	}
	return 0;
}
2023/3/12 12:30
加载中...