Submission #1341630

#TimeUsernameProblemLanguageResultExecution timeMemory
1341630iamhereforfunStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
141 ms18068 KiB
// Starcraft 2 enjoyer //

#include <bits/stdc++.h>

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define LSOne(X) ((X) & -(X))

const int N = 2e5 + 5;
const int K = 1e2 + 5;
const int M = 2e5 + 5;
const int LG = 20;
const long long INF = 1e18 + 5;
const int C = 26;
const int B = 1000;
const int MOD = 998244353;

int n, a[N], ans[N];
vector<int> v;
vector<pair<int, int>> each[N];
vector<array<int, 3>> all;

inline void solve()
{
    cin >> n;
    for (int x = 0; x < n; x++)
    {
        cin >> a[x];
        v.push_back(a[x]);
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    for (int x = 0; x < n; x++)
    {
        a[x] = lower_bound(v.begin(), v.end(), a[x]) - v.begin();
    }
    for (int x = 0; x < n; x++)
    {
        if (each[a[x]].empty())
        {
            all.push_back({x, x, a[x]});
            each[a[x]].push_back({x, x});
        }
        else
        {
            while (!all.empty())
            {
                if (all.back()[2] != a[x])
                {
                    each[all.back()[2]].pop_back();
                    all.pop_back();
                }
                else
                {
                    break;
                }
            }
            auto [l, r, i] = all.back();
            all.pop_back();
            each[a[x]].pop_back();
            each[a[x]].push_back({l, x});
            all.push_back({l, x, a[x]});
        }
    }
    for(auto &[l, r, i] : all)
    {
        for(int x = l; x <= r; x++)
        {
            ans[x] = i;
        }
    }
    for(int x = 0; x < n; x++)
    {
        cout << v[ans[x]] << " ";
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...