除了样例,其他的点都过了
? ? ? (此时状态)
手打栈。
#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;
}