cp-library

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

View the Project on GitHub qandori/cp-library

:heavy_check_mark: test/predecessor_set.test.cpp

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

検証問題

依存ライブラリ

コード

#define PROBLEM "https://judge.yosupo.jp/problem/predecessor_problem"
#include "../components/fast_io_bulk.hpp"
#include "../components/predecessor_set.hpp"

int main() {
	FastInput in;
	FastOutput out;
	int n = 0, q = 0;
	in.read(n), in.read(q);
	PredecessorSet set(in.token());
	read_unsigned_records<2>(in, q, [&](std::uint32_t type, std::uint32_t p) {
		if (type < 2) set.set(p, type == 0);
		else if (type == 2) out.println(int(set.contains(p)));
		else if (type == 3) { int x = set.next(p); out.println(x == n ? -1 : x); }
		else out.println(set.prev(p));
	});
}
Back to top page