80分求助
查看原帖
80分求助
669764
DragonForge楼主2024/4/1 19:11

真的很无语,为什么一直都是最后3个数据点 TLETLE 了,我都用了快读了,连 stackstack 的 sizesize 都用变量表示了,为什么会 TLETLE 呢 ??

这是我的代码:


#include <bits/stdc++.h>

using namespace std;

stack<int> st;
int x,n,ans,sizen;

inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0'||ch>'9'){
		if (ch=='-')
			f=-1;
		ch=getchar();
	}
	while (ch>='0'&&ch<='9'){
		x=x*10+ch-48;
		ch=getchar();
	}
	return x*f;
}

int main(){
    n=read();
    while(n--){
        x=read();
		int t=1;  
        while (sizen && x>=st.top()){
            if (st.top()==x)
				t++;
            ans++;
			st.pop();
			sizen--;
        }
        if (sizen){
			ans++;
        }
        while (t--){
			st.push(x);
			sizen++;
        }
    }
    printf("%d",ans);
    return 0;
}

求助

2024/4/1 19:11
加载中...