This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
int a[n+1];
for (int i=1; i<=n; i++) cin>>a[i];
int wh=n+1;
for (int i=2; i<=n; i++){
if (a[i-1]>a[i]){
wh=i;
break;
}
}
int ans=1;
set <int> s;
for (int i=1; i<wh; i++) s.insert(a[i]);
for (int i=wh; i<=n; i++){
auto it=s.lower_bound(a[i]+1);
int mx;
if (it==s.end()) mx=1e9;
else mx=(*it);
ans++;
bool ok=0;
for (int j=i+1; j<=n; j++){
if (a[j-1]>a[j]||a[j]>mx){
i=j-1;
ok=1;
break;
}
}
if (!ok) break;
}
cout<<ans<<'\n';
}
# | 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... |