제출 #1089090

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

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

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

    int n; cin >> n;
    map<int,int> mp;
    stack<pii> st; st.emplace(-1, 0);

    for (int i = 1; i <= n; i++) {
        int a; cin >> a;
        if (mp.count(a) && mp[a]) {
            while (st.size()) {
                int last = st.top().first; st.pop();
                mp[last]--;
                if (last == a) break;
            }
        }
        st.emplace(a, i);
        mp[a]++;
    }

    vector<int> ans;
    while (st.size()) {
        int clr, pos; tie(clr, pos) = st.top(); st.pop();
        if (pos) {
            int tt = pos - st.top().second;
            while (tt--) ans.push_back(clr);
        }
    }
    reverse(all(ans));
    for (int u : ans) cout << u << "\n";

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