66分,求指点
查看原帖
66分,求指点
807119
Gavin_Huang楼主2024/12/2 11:55
#include<bits/stdc++.h>
using namespace std;
long long n,a,x,b;
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);//让输入和输出分离
 
	stack<int> stk;//普通栈 
	stack<int> s;//单调栈 
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a==0){
			//TODO
			cin>>x;
			stk.push(x);
			if(i==0){
				//TODO
				s.push(x);
			}
			if(s.empty()==0 && s.top()<x){
				//TODO
				s.push(x);
			}
			
		}else if(a==1){
			if(s.empty()==0 &&  s.top()==stk.top()){
				//TODO
				
				s.pop();
			}
			stk.pop();

			
		}else if(a==2){
			//TODO
			if(s.empty()==1){
				//TODO
				cout<<0<<'\n';
			    continue;
			}
			cout<<s.top()<<'\n';
		}
		
	}
	
}
2024/12/2 11:55
加载中...