제출 #810667

#제출 시각아이디문제언어결과실행 시간메모리
810667alextodoranStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
161 ms15136 KiB
/**
 _  _   __  _ _ _  _  _ _
 |a  ||t  ||o    d | |o  |
| __    _| | _ | __|  _ |
| __ |/_  | __  /__\ / _\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



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

    int N;
    cin >> N;
    vector <pair <int, int>> v;
    map <int, int> cnt;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        cnt[x]++;
        if (cnt[x] > 1) {
            while (v.back().first != x) {
                cnt[v.back().first] -= v.back().second;
                cnt[x] += v.back().second;
                v.pop_back();
            }
            v.back().second = cnt[x];
        } else {
            v.push_back(make_pair(x, 1));
        }
    }
    for (pair <int, int> p : v) {
        for (int i = 0; i < p.second; i++) {
            cout << p.first << "\n";
        }
    }

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