結果
| 問題 | No.649 ここでちょっとQK! |
| コンテスト | |
| ユーザー |
みどりむし🦠
|
| 提出日時 | 2022-10-26 22:00:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 62 ms / 3,000 ms |
| コード長 | 3,039 bytes |
| 記録 | |
| コンパイル時間 | 850 ms |
| コンパイル使用メモリ | 96,996 KB |
| 最終ジャッジ日時 | 2025-02-08 12:52:49 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
#include <iostream>
/* #expanded [template.hpp] */
#include <iostream>
#ifdef LOCAL_JUDGE
#include<debug>
#define debug(...) Debug::debug(Debug::split(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#define DEBUG(...) do { Debug::DEBUG(nullptr, "\033[3;35m#" + to_string(__LINE__) + "\033[m "); Debug::DEBUG(__VA_ARGS__); Debug::DEBUG(nullptr, "\033[m\n"); } while(0);
#else
#define debug(...) { ; }
#define DEBUG(...) { ; }
#endif
#define INF32 2147483647
#define INF64 9223372036854775807LL
#define until(...) while(!(__VA_ARGS__))
#define REP(i,n) for(int i=0, i##_length=int(n); i<i##_length; ++i)
#define REPD(i,n) for(int i=(n)-1; i>=0; --i)
#define LOOP(n) REP(_$, (n))
#define FOR(i,l,r) for(ll i=(l), i##_last=ll(r); i<=i##_last; ++i)
#define FORD(i,l,r) for(ll i=(l), i##_last=ll(r); i>=i##_last; --i)
#define ITRP(x,v) for(auto x : (v))
#define ITRR(x,v) for(auto &x : (v))
#define ITR(x,v) for(const auto &x : (v))
#define ITRMP(x,y,v) for(auto [x, y] : (v))
#define ITRMR(x,y,v) for(auto &[x, y] : (v))
#define ITRM(x,y,v) for(const auto [x, y] : (v))
#define ALL(x) begin((x)),end((x))
#define RALL(x) rbegin((x)),rend((x))
#define $F first
#define $S second
using ll = long long;using ull = unsigned long long;using ld = long double;constexpr char ln = '\n';constexpr char spc = ' ';__attribute__((constructor)) inline void fast_io() { std::ios::sync_with_stdio(false), std::cin.tie(nullptr); }template<class T1, class T2> inline auto mod(T1 x, T2 r) { return (x%r+r)%r; }template<class T> inline bool chmax(T &a, T b) { return (a<b ? a=b, true : false); }template<class T> inline bool chmin(T &a, T b) { return (a>b ? a=b, true : false); }template<class T> auto operator<<(std::ostream &out, const T &val) -> decltype(val.val(), out)& {return out << val.val();}
/* [template.hpp] */
/* #expanded [kth_element.hpp] */
#include <vector>
#include <functional>
#include <queue>
template<class T, class Container = std::vector<T>, class CompA = std::less<T>, class CompB = std::greater<T>>struct KthElement {private:size_t K;std::priority_queue<T,Container,CompA> small;std::priority_queue<T,Container,CompB> large;public:KthElement(size_t K) : K(K) {}inline T get() const { return small.top(); }inline bool has() const { return small.size() == K; }inline void push(T v) {if(small.size() < K) {small.push(v);return;}T kth = small.top();if(v < kth) {small.pop(); small.push(v);large.push(kth);}else {large.push(v);}}inline void pop() {small.pop();if(large.empty()) return;T v = large.top(); large.pop();small.push(v);}};
/* [kth_element.hpp] */
//https://yukicoder.me/problems/no/649
signed main() {
int q, k; std::cin >> q >> k;
KthElement<ll> kth(k);
LOOP(q) {
int type; std::cin >> type;
if(type == 1) {
ll v; std::cin >> v;
kth.push(v);
}
if(type == 2) {
if(!kth.has()) {
std::cout << -1 << ln;
continue;
}
std::cout << kth.get() << ln;
kth.pop();
}
}
return 0;
}
みどりむし🦠