Submission #1241294

#TimeUsernameProblemLanguageResultExecution timeMemory
1241294GeforgsStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
153 ms19876 KiB
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <iterator>
#include <random>
#define ll long long
#define ld long double
#define inf (ll)(2*1e18)
#define sort(a) sort(a.begin(), a.end())
#define reverse(a) reverse(a.begin(), a.end())
#define pb push_back
#define endl "\n"
using namespace std;

void solve(){
    ll n, i;
    cin>>n;
    stack<ll> s;
    vector<ll> a(n);
    vector<ll> ans;
    map<ll, ll> m;
    for(i=0;i<n;++i){
        cin>>a[i];
        if(m[a[i]] > 0){
            while(a[s.top()] != a[i]){
                --m[a[s.top()]];
                s.pop();
            }
        }
        ++m[a[i]];
        s.push(i);
    }
    i = n-1;
    while(i >= 0){
        ans.pb(a[s.top()]);
        if(i == s.top()) s.pop();
        --i;
    }
    reverse(ans);
    for(auto el: ans){
        cout<<el<<' ';
    }
    cout<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    srand(time(nullptr));
    ll t=1;
//    cin>>t;
    for(;t>0;--t){
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...