提交时间:2022-07-20 11:50:41

运行 ID: 52701

#include<cstdio> typedef long long ll; int n; int a[1000005]; ll ans=0; int main(){ // freopen("height.in","r",stdin); scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",a+i); int mx=0,mxp=0; for(int i=1;i<=n;++i){ if(mx>a[i]){ int x=mxp; for(int j=1;j<mxp;++j) if(a[j]>a[i]){ x=j; break; } ans+=i-x; } else if(mx<a[i]) mx=a[i],mxp=i; } printf("%lld\n",ans); return 0; }