#include #include #include #include using namespace std; const int kMAX_N = 100010; int N; int a[kMAX_N]; void Solve() { reverse(a, a + N); priority_queue, greater > que; int ans = 0; for (int i = 0; i < N; i++) { if (que.empty() || (que.top() > a[i])) { que.push(a[i]); } else { while (!que.empty() && que.top() < a[i]) { que.pop(); ans++; } que.push(a[i]); } } cout << ans << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; for (int i = 0; i < N; i++) { cin >> a[i]; } Solve(); return 0; }