提交时间:2022-07-20 11:51:02

运行 ID: 52715

#include<bits/stdc++.h> using namespace std; const int N=1e6+10; int n,cnt; struct node{ int val,id; }a[N],b[N]; long long ans; int read(){ register int res=0,w=1; register char ch=getchar(); while(ch<'0'||ch>'9'){ ch=='-'?w=-1:w=w; ch=getchar(); } while(ch>='0'&&ch<='9') res=(res<<3)+(res<<1)+(ch^48),ch=getchar(); return res*w; } int main(){ n=read(); for(register int i=1;i<=n;i++) a[i].val=read(),a[i].id=i; b[++cnt]=a[1]; for(register int i=2;i<=n;i++){ bool flag=0; for(register int j=1;j<=cnt;j++){ if(b[j].val>a[i].val) { ans+=a[i].id-b[j].id; flag=1; break; } } if(!flag&&b[cnt].val!=a[i].val) b[++cnt]=a[i]; } printf("%lld\n",ans); return 0; }