답안 #234082

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
234082 2020-05-22T23:45:32 Z hugo_pm Editor (BOI15_edi) C++17
100 / 100
108 ms 17400 KB
#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() < 12U*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";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 10 ms 7552 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 10 ms 7424 KB Output is correct
6 Correct 9 ms 7424 KB Output is correct
7 Correct 10 ms 7552 KB Output is correct
8 Correct 8 ms 7424 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 15480 KB Output is correct
2 Correct 93 ms 15480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 12280 KB Output is correct
2 Correct 56 ms 13176 KB Output is correct
3 Correct 86 ms 11128 KB Output is correct
4 Correct 91 ms 15480 KB Output is correct
5 Correct 101 ms 15864 KB Output is correct
6 Correct 69 ms 12268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 10 ms 7552 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 10 ms 7424 KB Output is correct
6 Correct 9 ms 7424 KB Output is correct
7 Correct 10 ms 7552 KB Output is correct
8 Correct 8 ms 7424 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 89 ms 15480 KB Output is correct
11 Correct 93 ms 15480 KB Output is correct
12 Correct 52 ms 12280 KB Output is correct
13 Correct 56 ms 13176 KB Output is correct
14 Correct 86 ms 11128 KB Output is correct
15 Correct 91 ms 15480 KB Output is correct
16 Correct 101 ms 15864 KB Output is correct
17 Correct 69 ms 12268 KB Output is correct
18 Correct 95 ms 17400 KB Output is correct
19 Correct 90 ms 17272 KB Output is correct
20 Correct 108 ms 12020 KB Output is correct
21 Correct 90 ms 15352 KB Output is correct
22 Correct 101 ms 15864 KB Output is correct