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;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxn = 1e6+10;
multiset<int> st;
int arr[mxn];
int n;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
for(int i = 1;i<=n;i++)cin>>arr[i];
int ans = 0;
st.insert(mxn);
st.insert(0);
for(int i = 1;i<=n;){
int pt = i+1;
vector<int> v = {arr[i]};
while(pt<=n&&arr[pt]>=arr[pt-1]&&*st.lower_bound(arr[pt])<=*st.upper_bound(v[0])){
v.push_back(arr[pt]);
pt++;
}
ans++;
//cout<<i<<":"<<pt<<' '<<*st.lower_bound(arr[pt])<<' '<<*st.upper_bound(v[0])<<endl;
for(auto &j:v)st.insert(j);
i = pt;
}
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... |