제출 #494951

#제출 시각아이디문제언어결과실행 시간메모리
494951Ronin13Money (IZhO17_money)C++14
100 / 100
950 ms58044 KiB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define inf 1e9+1
#define linf 1e18+1
using namespace std;
const int NMAX=1e6+1;


void solve(){
    int n;cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++)cin>>a[i];
    set<int>st;
    st.insert(inf);
    int l=1;
   int r=2;
    int cnt=0;
    while(r<=n){

        int x;
        if(st.size()==0)x=inf;
        else x=*st.upper_bound(a[l]);
        if((a[r]>=a[r-1])&&(x>=a[r])){
            r++;
        }
        else{
            cnt++;
            for(int i=l;i<r;i++){
                st.insert(a[i]);
            }
            l=r;
            r++;
        }
    }
    cnt++;
    cout<<cnt<<"\n";
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int test=1;//cin>>test;
    while(test--)solve();
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...