제출 #1181757

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    int a[n], odp[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector<pair<int,int>> v; multiset<int> ms;
    v.push_back({0,a[0]}); ms.insert(a[0]);
    for (int i = 1; i < n; i++) {
        if (ms.find(a[i]) != ms.end()) {
            while (v.back().second != a[i])
                ms.erase(ms.find(v.back().second)), v.pop_back();
        }
        else
            v.push_back({i,a[i]}), ms.insert(a[i]);
    }
    for (int i = n-1; i >= 0; i--) {
        if (i < v.back().first)
            v.pop_back();
        odp[i] = v.back().second;
    }
    for (int i = 0; i < n; i++)
        cout << odp[i] << endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...