提交时间:2022-07-20 11:59:29

运行 ID: 52804

#include <bits/stdc++.h> using namespace std; const int maxn = 1000000 + 10; long long n; long long a[maxn]; long long ans = 0; int main() { //freopen("height.in", "r", stdin); scanf("%d", &n); long long mx = -1; for(int i = 0; i < n; ++i) { scanf("%d", &a[i]); if(i == 0) { mx = a[i]; continue; } if(mx < a[i]) { mx = max(mx, a[i]); continue; } mx = max(mx, a[i]); for(int j = 0; j < i; ++j) { if(a[j] > a[i]) { ans += i - j; //printf("a[%d] > a[%d], ans += %d\n", j, i, i - j); break; } } } cout<<ans<<endl; //fclose(stdin); return 0; }