제출 #931502

#제출 시각아이디문제언어결과실행 시간메모리
931502PringStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
199 ms34036 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef MIKU
#define debug(x...) cout << "[" << #x << "] : ", dout(x)
void dout() { cout << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;

const int MXN = 200005;
int n, a[MXN];
pii dist[MXN];
vector<int> st[MXN], ST;
map<int, int> M;

void DIST() {
    FOR(i, 0, n) dist[i] = mp(a[i], i);
    sort(dist, dist + n);
    for (int i = 0, j = 0; i < n; i = j) {
        while (j < n && dist[i].fs == dist[j].fs) j++;
        M[i] = dist[i].fs;
        FOR(k, i, j) dist[k].fs = i;
    }
    FOR(i, 0, n) a[dist[i].sc] = dist[i].fs;
}

void miku() {
    cin >> n;
    FOR(i, 0, n) cin >> a[i];
    DIST();
    FOR(i, 0, n) {
        if (st[a[i]].size()) {
            int lst = st[a[i]].back();
            while (ST.back() != lst) {
                st[a[ST.back()]].pop_back();
                ST.pop_back();
            }
        }
        st[a[i]].push_back(i);
        ST.push_back(i);
    }
    int now = -1, id = 0;
    FOR(i, 0, n) {
        if (ST[id] == i) {
            id++;
            now = a[i];
        }
        cout << M[now] << '\n';
    }
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(iostream::failbit);
    miku();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...