This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |