제출 #1038238

#제출 시각아이디문제언어결과실행 시간메모리
1038238LOLOLOMoney (IZhO17_money)C++17
100 / 100
623 ms58196 KiB
#include <bits/stdc++.h>
typedef long long ll;

#define           f    first
#define           s    second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
using namespace std;

const int N = 1e6 + 10;
int a[N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    set <int> st;
    st.insert(1e9);

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        int lim = *st.upper_bound(a[i]);
        st.insert(a[i]);

        int j = i;
        while (j + 1 <= n && a[j + 1] >= a[j] && a[j + 1] <= lim) {
            j++;
            st.insert(a[j]);
        }

        i = j;
        cnt++;
    }

    cout << cnt << '\n';
    return 0;
}

/*
4 3
2 3
2 6 2
2 4 2
6 5 1
1 2 3
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...