#include <bits/stdc++.h>
//qwerty47924692
using namespace std;
using ll = long long;
const ll N=2e5+29;
const string br="617283";
ll n,a[N],ans=1e18;
vector<ll>v;
set<ll>s;
bool cn(vector<ll> &v,ll x=0){
ll mn=v.front();
ll mx=v.back();
auto it=s.lower_bound(mx);
if(it==s.begin()){
goto can;
}
--it;
if(mn<*it){
return 0;
}
can:;
if(x==1){
for(ll i:v){
s.insert(i);
}
}
return 1;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n;
ll ans=1;
for(ll i=1;i<=n;i++){
cin>>a[i];
v.push_back(a[i]);
if(a[i]<a[i-1]||!cn(v)){
v.pop_back();
cn(v,1);
v.clear();
v.push_back(a[i]);
ans++;
}
}
cout<<ans;
}
# | 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... |