제출 #1015744

#제출 시각아이디문제언어결과실행 시간메모리
1015744phoenixMoney (IZhO17_money)C++17
100 / 100
894 ms54180 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 1'000'100;

int n;

#define viit vector<set<int>::iterator>

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;

    set<int> proceeded;
    viit pos; 
    vector<int> buffer; 
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        viit cur = {proceeded.lower_bound(a), proceeded.upper_bound(a)};

        bool flag = false;
        for (auto c1 : pos) for (auto c2 : cur)
            flag |= (c1 == c2);

        if (!buffer.empty() && buffer.back() <= a && flag) {
            viit v;
            for (auto c1 : pos) {
                bool f = false;
                for (auto c2 : cur) f |= (c1 == c2);
                if (f) 
                    v.push_back(c1);
            }
            pos = v;
        } else {
            for (int c : buffer) 
                proceeded.insert(c);
            buffer.clear();
            ans++;
            pos = {proceeded.lower_bound(a), proceeded.upper_bound(a)};
        }
        buffer.push_back(a);
    }

    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...