#include<bits/stdc++.h>
using namespace std;
stack<int>a;
stack<int>b;
int n;
int c;
int d;
int max1=0;
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>c;
if(c==0){
cin>>d;
if(d>=max1){
max1=d;
}
b.push(max1);
a.push(d);
} else if(c==1){
if(a.empty()){
continue;
} else{
a.pop();
b.pop();
}
} else{
if(a.empty()){
cout<<0<<endl;
} else{
cout<<b.top()<<endl;
}
}
}
return 0;
}
为什么?