제출 #1125212

#제출 시각아이디문제언어결과실행 시간메모리
1125212omar1312Stone Arranging 2 (JOI23_ho_t1)C++20
25 / 100
2093 ms7612 KiB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
const int mod = 1000000007;
const int N = 200005;
ll a[N+2], dp[N+2], col[N+2];
void solve(){
    int n;
    cin>>n;
    for(int i = 0; i < n; i++){
        cin>>a[i];
        col[i] = a[i];
    }
    stack<array<ll, 2>> s;
    map<ll, ll> mp;
    vector<array<ll, 2>> v;
    for(int i = 0; i < n; i++){
        if(mp[a[i]]){
            while(s.top()[1] != a[i]){
                mp[s.top()[1]]--;
                s.pop();
            }
            v.pb({-i, s.top()[0]});
        }
        else{
            mp[a[i]]++;
            s.push({i, a[i]});
        }
    }
    // for(auto[i, j] : v){
    //  cout<<j<<' '<<-i<<'\n';
    // }
    sort(all(v));
    int it = v.size() - 1;
    while(it != -1){
        array<ll, 2> cur = {v[it][1], -v[it][0]};
        for(int i = cur[0]; i <= cur[1]; i++){
            col[i] = col[cur[0]];
        }
        --it;
    }
    for(int i = 0; i < n; i++){
        cout<<col[i]<<' ';
    }
}
int main(){
cin.tie(0)->sync_with_stdio(0);
    int tt = 1;
    //cin>>tt;
    while(tt--){
        solve();
        cout<<'\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...