제출 #1136125

#제출 시각아이디문제언어결과실행 시간메모리
1136125fzyzzz_zStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
128 ms14004 KiB
#include <bits/stdc++.h>
using namespace std; 

using ll = long long; 

int32_t main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(0); 

    int n; 
    cin >> n; 

    set<int> colors; 
    vector<pair<int, int>> starts; 

    for (int i = 0; i < n; ++i) {
        int x; 
        cin >> x; 
        if (colors.find(x) != colors.end()) {
            while (starts.back().first != x) {
                colors.erase(starts.back().first); 
                starts.pop_back(); 
            }
        } else {
            colors.insert(x); 
            starts.push_back({x, i}); 
        }
    }

    vector<int> ans(n, -1); 
    for (auto [col, pos]: starts) {
        ans[pos] = col; 
    }

    for (int i = 0; i < n; ++i) {
        if (ans[i] == -1) ans[i] = ans[i - 1]; 
        cout << ans[i] << '\n'; 
    }


    return 0; 
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...