이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;
const int maxElem = 3e5 + 5;
int nbElem;
int level[maxElem];
int lastEdit[maxElem];
int parent[maxElem];
struct comp {
bool operator()(int a, int b) {
return level[a] < level[b];
}
};
using PQ = priority_queue<int, vector<int>, comp>;
PQ hidden[maxElem];
void merge(PQ &dest, PQ &eaten) {
if (dest.size() < eaten.size()) dest.swap(eaten);
while (!eaten.empty()) {
dest.push(eaten.top());
eaten.pop();
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> nbElem;
for (int iElem = 1; iElem <= nbElem; ++iElem) {
cin >> lastEdit[iElem];
level[iElem] = max(0, -lastEdit[iElem]);
}
PQ cur;
for (int iElem = nbElem; iElem >= 1; --iElem) {
PQ nxt;
while (!cur.empty() && level[cur.top()] > level[iElem]) {
parent[cur.top()] = iElem-1;
merge(nxt, hidden[cur.top()]);
cur.pop();
}
nxt.push(iElem);
hidden[iElem].swap(cur);
cur.swap(nxt);
}
for (int iElem = 1; iElem <= nbElem; ++iElem) {
if (level[iElem] > 0) {
lastEdit[iElem] = lastEdit[parent[iElem]];
}
cout << lastEdit[iElem] << "\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... |