제출 #234083

#제출 시각아이디문제언어결과실행 시간메모리
234083hugo_pmEditor (BOI15_edi)C++17
100 / 100
110 ms17400 KiB
#include <algorithm> #include <cassert> #include <iostream> #include <numeric> #include <vector> using namespace std; using ll = long long; using PQ = vector<int>; const int maxElem = 3e5 + 5; PQ hidden[maxElem]; int level[maxElem]; int lastEdit[maxElem]; int parent[maxElem]; int nbElem; bool comp(const int &a, const int &b) { return level[a] < level[b]; } void merge(PQ &dest, PQ &eaten) { if (dest.size() < eaten.size()) swap(dest, eaten); if (dest.size() < 35U*eaten.size()) { dest.insert(dest.end(), eaten.begin(), eaten.end()); make_heap(dest.begin(), dest.end(), comp); return; } for (int x : eaten) { dest.push_back(x); push_heap(dest.begin(), dest.end(), comp); } } 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.front()] > level[iElem]) { parent[cur.front()] = iElem-1; merge(nxt, hidden[cur.front()]); pop_heap(cur.begin(), cur.end(), comp); cur.pop_back(); } nxt.push_back(iElem); push_heap(nxt.begin(), nxt.end(), comp); merge(hidden[iElem], 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...