제출 #802695

#제출 시각아이디문제언어결과실행 시간메모리
802695someoneEditor (BOI15_edi)C++14
100 / 100
80 ms31168 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 3e5 + 42, INF = 1e18 + 42;

int n, lvl[N], par[N], val[N];
priority_queue<pair<int, int>> hid[N];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> lvl[i];
        lvl[i] = -lvl[i];
    }

    priority_queue<pair<int, int>> cur, nxt;
    for(int i = n-1; i > -1; i--) {
        par[i] = i;
        swap(nxt, cur);
        while(!nxt.empty()) nxt.pop();
        nxt.push({max(lvl[i], 0ll), i});
        while(!cur.empty() && cur.top().first > max(lvl[i], 0ll)) {
            int id = cur.top().second;
            cur.pop();
            par[id] = i;
            if((int)hid[id].size() > (int)nxt.size())
                swap(hid[id], nxt);
            while(!hid[id].empty()) {
                nxt.push(hid[id].top());
                hid[id].pop();
            }
        }
        swap(cur, hid[i]);
    }
    for(int i = 0; i < n; i++)
        if(lvl[i] < 0)
            cout << (val[i] = -lvl[i]) << '\n';
        else
            cout << (val[i] = val[par[i]-1]) << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...