#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ins insert
#define pll pair<ll, ll>
#define vec vector
#define ss second
#define ff first
using namespace std;
const ll inf = 1e17;
void _(){
ll n; cin >> n; ll last = 0;
vec<ll>a(n + 1, -1); multiset<ll>nw;
ll ans = 0; nw.ins(inf);
for(ll i = 0; i < n; i++) cin >> a[i];
for(ll i = 1; i <= n; i++){
if(a[i - 1] > a[i]){
while(last < i){
ll up = *nw.upper_bound(a[last]);
while(*nw.lower_bound(a[last]) <= up and last < i) nw.ins(a[last++]);
ans++;
}
}
} cout << ans;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr); _();
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |