제출 #1357257

#제출 시각아이디문제언어결과실행 시간메모리
1357257kawhietMoney (IZhO17_money)C++20
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 47
#endif

constexpr int inf = 1e9;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    set<int> l, r;
    l.insert(0);
    r.insert(inf);
    int ans = 0, pos = 0;
    for (; pos < n; pos++) {
        ans++;
        int x = *prev(l.upper_bound(a[pos]));
        int y = *r.lower_bound(a[pos]);
        l.insert(a[pos]);
        r.insert(a[pos]);
        while (pos + 1 < n && a[pos + 1] >= a[pos]) {
            if (x <= a[pos + 1] && a[pos + 1] <= y) {
                pos++;
                l.insert(a[pos]);
                r.insert(a[pos]);
            } else {
                break;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…