結果

問題 No.3298 K-th Slime
ユーザー elphe
提出日時 2025-10-05 14:11:37
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,685 bytes
コンパイル時間 3,088 ms
コンパイル使用メモリ 289,532 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-05 14:11:51
合計ジャッジ時間 5,146 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21 RE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

[[nodiscard]] static inline std::vector<uint_least64_t> solve(const uint_fast32_t N, const uint_fast32_t K, const uint_fast32_t Q, const std::vector<uint_least32_t>& A, const std::vector<std::pair<char, uint_least32_t>>& queries) noexcept
{
	std::priority_queue<uint_least64_t> pq_under;
	std::priority_queue<uint_least64_t, std::vector<uint_least64_t>, std::greater<uint_least64_t>> pq_over;
	for (uint_fast32_t i = 0; i < K; ++i)
		pq_under.push(A[i]);
	for (uint_fast32_t i = K; i < N; ++i)
		pq_over.push(A[i]);

	std::vector<uint_least64_t> ans;
	ans.reserve(Q);
	for (const auto& [t, x] : queries)
	{
		const auto kth_element = pq_under.top();
		switch (t)
		{
		case '1':
			if (x >= kth_element)
				pq_over.push(x);
			else
				pq_over.push(kth_element), pq_under.pop(), pq_under.push(x);
			break;

		case '2':
			if (kth_element + x <= pq_over.top())
				pq_under.pop(), pq_under.push(kth_element + x);
			else
				pq_under.pop(), pq_under.push(pq_over.top()), pq_over.pop(), pq_over.push(kth_element + x);
			break;

		case '3':
			ans.push_back(kth_element);
			break;
		}
	}

	return ans;
}

static inline void output(const std::vector<uint_least64_t>& ans) noexcept
{
	for (const auto& ans : ans)
		std::cout << ans << '\n';
}

int main()
{
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);

	uint_fast32_t N, K, Q;
	std::cin >> N >> K >> Q;
	std::vector<uint_least32_t> A(N);
	std::vector<std::pair<char, uint_least32_t>> queries(Q);
	for (auto& a : A) std::cin >> a;
	for (auto& [t, x] : queries)
	{
		std::cin >> t;
		if (t != '3') std::cin >> x;
	}

	std::sort(A.begin(), A.end());
	output(solve(N, K, Q, A, queries));
	return 0;
}
0