提交时间:2022-07-20 11:50:54
运行 ID: 52706
#include<iostream> #include<cstdio> #define ll long long using namespace std; int n,a,b[1000005]; ll ans; int find(int l,int r,int lmt){ int mid; while(l<r){ mid=l+r>>1; if(b[mid]<=lmt) l=mid+1; else r=mid; } return l; } int main(){ scanf("%d",&n); for(int i=1;i<=n;i+=1){ scanf("%d",&a); b[i]=max(b[i-1],a); ans+=1ll*(i-find(1,i,a)); } printf("%lld\n",ans); return 0; }