제출 #1257525

#제출 시각아이디문제언어결과실행 시간메모리
1257525medaaMoney (IZhO17_money)C++20
100 / 100
893 ms51304 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

void SOLVE() {
    int n; cin >> n;
    vector<int> a(n);
    for(auto & val : a) cin >> val;
    int counter = 0;
    set<pair<int, int>> ms;
    ms.insert({0, *max_element(a.begin(), a.end()) + 1});

    for(int i = 0; i < n;){
        int mn = a[i], j = i;
        auto it = ms.lower_bound({mn, 1e9});
        it--;
        pair<int, int> c = *it;
        //cout << "H " << c.first << " " << c.second << endl;
        while(j + 1 < n && a[j + 1] >= a[j] && a[j + 1] <= c.second){
            j++;
        }
        ms.erase(ms.find(c));
        ms.insert({c.first, a[i]});
        for(int k = i; k < j; k++){
            ms.insert({a[k], a[k + 1]});
        }
        ms.insert({a[j], c.second});
        counter++;
        // for(auto [x, y] : ms) cout << x << " " << y << endl;
        // cout << endl;
        i = j + 1;
    }
    cout << counter << endl;
}
signed main(){
    ios_base::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int o_o = 1; //cin >> o_o;
    while(o_o --) SOLVE();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...