提交时间:2022-07-20 12:02:47
运行 ID: 52842
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define int ll const int maxn=1e6+10; const int inf=1e9+7; int n,ans,a[maxn],mx[maxn],mxx=-1; inline int read() { int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')w=-1; ch=getchar(); } while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } signed main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); n=read(); for(int i=1; i<=n; ++i) { a[i]=read(); if(a[i]>=mxx) { mxx=a[i]; mx[i]=i; } else mx[i]=mx[i-1]; } // for(int i=1; i<=n; ++i) // cout<<mx[i]<<' '; // puts(""); for(int i=1; i<=n; ++i) ans+=i-mx[i]; printf("%lld\n",ans); return 0; }