제출 #1241332

#제출 시각아이디문제언어결과실행 시간메모리
1241332nasjesStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
198 ms22820 KiB
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <iterator>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll dim = 1e6+7;
//const ll mod = 1e9 + 7;
const ll inf = 1e18 + 77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>

ll n, l;
ll a[dim];
int main() {
    stack<pll> st;
    map<ll, ll>mp;
    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>a[i];
        if(mp[a[i]]>0){
            while(st.size()>0 && st.top().fi!=a[i]){
                mp[st.top().fi]--;
                st.pop();
            }
        }
        else{
            mp[a[i]]++;
            st.push({a[i], i});
        }
    }
    vector<pll> ans;
    while(st.size()>0){
        //cout<<st.top().fi<<" "<<st.top().se<<endl;
        ans.pb(st.top());
        st.pop();
    }
    reverse(ans.begin(), ans.end());
    for(int i=0; i<ans.size(); i++){
        ll next=ans[i+1].se-1;
        ll sz=ans.size();
        if(i==sz-1)next=n;
        for(int j=ans[i].se; j<=next; j++){
            cout<<ans[i].fi<<endl;
        }
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...