提交时间:2022-07-20 12:06:29

运行 ID: 52881

#include <bits/stdc++.h> using namespace std; const int MXN = 1e6; int n, a[MXN], ans; struct node { int val, pos; }cmp; int main() { ios::sync_with_stdio(false); cin >> n; for(int i(1); i <= n; i++) cin >> a[i]; cmp.val = a[1], cmp.pos = 1; for(int i(2); i <= n; i++) { if(a[i] < cmp.val) { ans += (i - cmp.pos); } if(a[i] == cmp.val) continue; if(a[i] > cmp.val) { cmp.val = a[i]; cmp.pos = i; } } cout << ans << endl; return 0; }