24分,WA了一片求助
查看原帖
24分,WA了一片求助
521283
wangif424楼主2022/10/5 22:53
#include<bits/stdc++.h>
#define int long long
using namespace std;
stack<pair<int,int> > t;
int n,h,ans,s;
signed main(){
	cin >> n;
	while(n--){
		s=1;
		cin >> h;
		while(!t.empty()){
			if(t.top().first<=h){
				ans+=t.top().second;
				if(t.top().first==h)s+=t.top().second;
				t.pop();
			}else{
				ans+=s;
				break;
			}
		}
		t.push(make_pair(h,s));
	}
	cout << ans;
	return 0;
}

2022/10/5 22:53
加载中...