这能错???
查看原帖
这能错???
1328264
wjy7777楼主2025/1/25 12:22

0分代码:

#include<bits/stdc++.h>
using namespace std;
stack<int> st;
int x,a[200005],Max=0,t=0,b[200005],e=0;
int main(){
	int n,o;
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>x;
		if (x==0){
			cin>>o;
			if (o>a[t]){
				a[++t]=o;
			}
			else{
				a[++t]=a[t-1];
			}
			st.push(o);
		}
		else if (x==1){
			if (!(st.empty())){
				st.pop();
			}
			else{
				continue;
			}
			if (t>0){
				t--;
			}
		}
		else if (x==2){
			if (st.empty()){
				b[e++]=0;
			}
			else{
				b[e++]=a[t];
			}
		}
	}
	for (int i=0;i<e;i++){
		cout<<b[i]<<endl;
	}
	return 0;
}


样例都是对的

暴力49分代码:

#include<bits/stdc++.h>
using namespace std;
stack<int> st;
int x,a[100000005],Max=0;
void themax(){
	int w=Max;
	Max=0;
	for (int i=0;i<=w;i++){
		if (a[i]>=1){
			Max=max(Max,i);
		}
	}
}
int main(){
	int n,o;
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>x;
		if (x==0){
			cin>>o;
			st.push(o);
			a[o]++;
			Max=max(Max,o);
		}
		else if (x==1){
			if (!(st.empty())){
				a[st.top()]--;
				st.pop();
				themax();
			}
			else{
				continue;
			}
		}
		else if (x==2){
			if (st.empty()){
				cout<<0<<endl;
			}
			else{
				cout<<Max<<endl;
			}
		}
	}
	return 0;
}

Help me!!!

2025/1/25 12:22
加载中...