제출 #782327

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,y,a;
    cin >> n;
    vector<int> p(n);
    vector<int> c(n);
    map<int,bool> haha;
    for(int i = 0; i < n; i++) {
        cin >> a;
        if(haha[a]) {
            y = i-1;
            while(y != -1 && c[y] != a) {
                haha[c[y]] = false;
                y = p[y];
            }
            if(y != -1) {
                y = p[y];
            }
            p[i] = y;
        }
        else {
            haha[a] = true;
            p[i] = i-1;
        }
        c[i] = a;
    }
    y = n-1;
    vector<int> ans(n);
    while(y != -1) {
        ans[y] = c[y];
        y = p[y];
    }
    for(int i = n-1; i >= 0; i--) {
        if(ans[i] == 0) {
            ans[i] = ans[i+1];
        }
    }
    for(int i = 0; i < n; i++) {
        cout << ans[i] << " ";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...