24P分求助P1823(题目板块下挂了一天没人,违规紫衫)
  • 板块题目总版
  • 楼主wangif424
  • 当前回复2
  • 已保存回复2
  • 发布时间2022/10/7 00:48
  • 上次更新2023/10/27 08:23:35
查看原帖
24P分求助P1823(题目板块下挂了一天没人,违规紫衫)
521283
wangif424楼主2022/10/7 00:48
#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/7 00:48
加载中...