#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
void SOLVE() {
int n; cin >> n;
vector<int> a(n);
for(auto & val : a) cin >> val;
int counter = 0;
multiset<pair<ll, ll>> ms;
ms.insert({0, *max_element(a.begin(), a.end()) + 1});
for(int i = 0; i < n;){
int mn = a[i], j = i;
auto it = ms.lower_bound({mn, 1e9});
it--;
pair<ll, ll> c = *it;
//cout << "H " << c.first << " " << c.second << endl;
while(j + 1 < n && a[j + 1] >= a[j] && a[j + 1] <= c.second){
j++;
}
ms.erase(ms.find(c));
ms.insert({c.first, a[i]});
for(int k = i; k < j; k++){
ms.insert({a[k], a[k + 1]});
}
ms.insert({a[j], c.second});
counter++;
// for(auto [x, y] : ms) cout << x << " " << y << endl;
// cout << endl;
i = j + 1;
}
cout << counter << endl;
}
signed main(){
ios_base::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int o_o = 1; //cin >> o_o;
while(o_o --) SOLVE();
return 0;
}
# | 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... |