제출 #1324564

#제출 시각아이디문제언어결과실행 시간메모리
1324564tomthuy123Stone Arranging 2 (JOI23_ho_t1)C++20
0 / 100
0 ms336 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const ll MOD=1000000007;

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

    ll n;
    cin >> n;
    vector<ll> lst(n+1);
    map<ll,ll> Reference;
    for(ll i=1;i<=n;i++){
        cin >> lst[i];
        Reference[lst[i]]=0;
    }
    stack<vector<ll>> OrderLst;
    for(ll i=1;i<=n;i++){
        ll Curr=lst[i];

        if(OrderLst.empty()){
            OrderLst.push({Curr,i,i});
            Reference[Curr]=1;
            continue;
        }

        vector<ll> Last=OrderLst.top();
        if(Last[0]==Curr){
            Last[2]=i;
        }
        else if(Reference[Curr]==0){
            OrderLst.push({Curr,i,i});
            Reference[Curr]=1;
        }
        else{
            while(!OrderLst.empty() and OrderLst.top()[0]!=lst[i]){
                Reference[OrderLst.top()[0]]=0;
                OrderLst.pop();
            }
            OrderLst.top()[2]=i;
        }
    }
    vector<ll> ans(n+1);
    while(!OrderLst.empty()){
        vector<ll> Curr=OrderLst.top();
        OrderLst.pop();
        for(ll i=Curr[1];i<=Curr[2];i++){
            ans[i]=Curr[0];
        }
    }
    for(ll i=1;i<=n;i++){
        cout << ans[i] << "\n";
    }
    

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...