| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1285030 | okahak71 | Money (IZhO17_money) | C++20 | 0 ms | 0 KiB |
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#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 << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); _();
}
