제출 #1343982

#제출 시각아이디문제언어결과실행 시간메모리
1343982nguyenkhangninh99Stone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
150 ms19532 KiB

#include <bits/stdc++.h>
using namespace std;

#define int long long 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n; cin >> n;
    vector<int> a(n + 1), b(n + 1), pos;

    map<int, int> cnt;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        while(cnt[a[i]] && !pos.empty() && a[pos.back()] != a[i]){
            cnt[a[pos.back()]]--;
            pos.pop_back();
        }
        b[i] = (pos.empty() ? 0 : pos.back());
        pos.push_back(i);
        cnt[a[i]]++;
    }
    for(int i = n; i >= 1; i = b[i]){
        for(int j = i; j > b[i]; j--) a[j] = a[i];
    }
    for(int i = 1; i <= n; i++) cout << a[i] << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...