提交时间:2024-04-19 13:22:34

运行 ID: 143852

#include<bits/stdc++.h> using namespace std; long long n,cnt=0; struct pl{ long long h,c=1; }o[500050]; stack<pl> q; int main(){ cin>>n; for(int i=1;i<=n;i++){ cin >> o [i] . h; while(! q . empty () && o [i] . h >= q . top () . h){ cnt += q . top () . c; if(o [i] . h == q . top () . h)o [i] . c += q . top () . c; q . pop (); } if(! q . empty ())cnt++; q.push( o [i] ); } cout<<cnt; return 0; }