제출 #1333435

#제출 시각아이디문제언어결과실행 시간메모리
1333435edga1Stone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
145 ms15080 KiB
#include <bits/stdc++.h>

using namespace std;

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second

const int N = 2e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

int main(){
    FIO
    int n; cin>>n;
    map<int,int> mp;
    stack<array<int,3>> s;
    for(int i=0; i<n; i++){
        int a; cin>>a;
        int l=i,r=i;
        if(mp[a]>0){
            while(l==i){
                auto au=s.top();
                s.pop();
                mp[au[0]]--;
                if(au[0]==a) l=au[1];
            }
        }
        mp[a]++;
        s.push({a,l,r});
    }
    vector<int> atb;
    while(!s.empty()){
        auto au=s.top();
        s.pop();
        for(int i=au[1]; i<=au[2]; i++) atb.pb(au[0]);
    }
    for(int i=n-1; i>=0; i--) cout<<atb[i]<<'\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...