cp-library

競技プログラミング用 C++ ライブラリ

View the Project on GitHub qandori/cp-library

:heavy_check_mark: test/persistent_heap.test.cpp

test/persistent_heap.test.cpp · GitHub で見る

検証問題

依存ライブラリ

コード

#define PROBLEM "https://judge.yosupo.jp/problem/persistent_queue"
#include "../data_structure/persistent_heap.hpp"
#include <iostream>
#include <utility>
#include <vector>

int main() {
	std::cin.tie(nullptr)->sync_with_stdio(false);
	int q;
	std::cin >> q;
	PersistentHeap<std::pair<int, int>> heap;
	std::vector<decltype(heap)::root_type> roots(q + 1);
	for (int i = 1; i <= q; ++i) {
		int type, k;
		std::cin >> type >> k;
		if (type == 0) { int x; std::cin >> x; roots[i] = heap.push(roots[k + 1], {i, x}); }
		else { std::cout << heap.top(roots[k + 1]).second << '\n'; roots[i] = heap.pop(roots[k + 1]); }
	}
}
Back to top page