cp-library

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

View the Project on GitHub qandori/cp-library

:heavy_check_mark: test/persistent_queue_batch.test.cpp

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

検証問題

依存ライブラリ

コード

#define PROBLEM "https://judge.yosupo.jp/problem/persistent_queue"
#include "data_structure/persistent_queue.hpp"
#include "components/fast_io.hpp"
#include <vector>

int main() {
	FastInput input;
	FastOutput output;
	int q = 0;
	input.read(q);
	PersistentQueue<int> queue;
	queue.reserve(q);
	using Root = decltype(queue)::root_type;
	std::vector<Root> roots(q + 1), queries;
	queries.reserve(q);
	for (int i = 1; i <= q; ++i) {
		int type = 0, k = 0;
		input.read(type), input.read(k);
		if (type == 0) { int x = 0; input.read(x); roots[i] = queue.push(roots[k + 1], x); }
		else { queries.push_back(roots[k + 1]); roots[i] = queue.pop(roots[k + 1]); }
	}
	for (int value : queue.front_many(queries)) output.println(value);
}
Back to top page