Submission #1281747

#TimeUsernameProblemLanguageResultExecution timeMemory
1281747hssaan_arifStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
396 ms30512 KiB
// #include <me>
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"
#define pb push_back
#define int long long

const int N = 3e5 + 5, M = 1e9 + 7, LG = 20;

int n , x;

void solve(){
    cin >> n;
    int col[n+1] = {} , ans[n+1] = {};
    map<int,int> ls , rp;
    for (int i = 1 ; i <= n ; i++){
        cin >> x;
        if (ls[x] == 0){
            ls[x] = i;
            col[i] = i;
            rp[i] = x;
        }else{
            col[i] = col[ls[x]];
        }
    }
    ls.clear();
    for (int i = 1 ; i <= n ; i++){
        ls[col[i]] = i;
    }
    for (int i = 1 ; i <= n ; i++){
        // cout << i << endl;
        int j = ls[col[i]] , x = rp[col[i]];
        while(i <= n && i <= j){
            ans[i] = x;
            i++;
        }
        i--;
    }
    for (int i = 1 ; i <= n ; i++){
        cout << ans[i] << endl;
    }
    
}

signed main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int ts = 1;
    // cin >> ts;
    while(ts--){
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...