제출 #972965

#제출 시각아이디문제언어결과실행 시간메모리
972965thinknoexitStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
77 ms15748 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
unordered_map<int, int> mp;
int a[200200];
int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    stack<pair<int, int>> st;
    for (int i = 1;i <= n;i++) {
        int t;
        cin >> t;
        if (mp[t] != 0) {
            while (!st.empty() && st.top().first != t) {
                int v = st.top().first, idx = st.top().second;
                st.pop();
                if (st.empty()) mp[v] -= idx;
                else mp[v] -= idx - st.top().second;
            }
        }
        if (!st.empty()) mp[t] += i - st.top().second;
        else mp[t] += i;
        st.push({ t, i });
    }
    while (!st.empty()) a[st.top().second] = st.top().first, st.pop();
    for (int i = n;i >= 1;i--) {
        if (a[i] == 0) a[i] = a[i + 1];
    }
    for (int i = 1;i <= n;i++) {
        cout << a[i] << '\n';
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...