全 T 求调
查看原帖
全 T 求调
584596
Anoif_Ifsky_rnfmabj楼主2024/12/22 11:48

在学校 OJ 上看到了一模一样的题目,但是在学校 OJ 上是全 A 的,提交到洛谷上就 TLE 了。

Code:

#include<bits/stdc++.h>
using namespace std;
stack<int> st;
int goods[214514]={-1},tmp=0;
void in(int x){
	if(x>goods[tmp]) goods[++tmp]=x;
	else tmp++,goods[tmp]=goods[tmp-1];
	st.push(x);
}
void out(){ if(st.size()>0) st.pop(); if(tmp>0) tmp--;}
int search(){
	if(st.size()==0)  cout<<0<<endl;
	else cout<<goods[tmp]<<endl;
}
int main(){
	int n; cin>>n;
	for(int i=1;i<=n;i++){
		int a,x; cin>>a;
		if(a==0) cin>>x,in(x);
		if(a==1) out();
		if(a==2) search();
	}
	return 0;
}
2024/12/22 11:48
加载中...