結果
| 問題 | No.649 ここでちょっとQK! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-16 20:22:16 |
| 言語 | C++17(gcc12) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 73 ms / 3,000 ms |
| コード長 | 1,164 bytes |
| 記録 | |
| コンパイル時間 | 2,127 ms |
| コンパイル使用メモリ | 159,620 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-03-08 21:16:30 |
| 合計ジャッジ時間 | 4,930 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
32 | scanf("%d", &t);
| ~~~~~^~~~~~~~~~
main.cpp:35:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
35 | scanf("%lld", &v);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;
int main() {
int q, k;
cin >> q >> k;
priority_queue<ll> Q;
GPQ<ll> Q2;
while(q--){
int t;
scanf("%d", &t);
if(t == 1){
ll v;
scanf("%lld", &v);
Q.emplace(v);
if(Q.size() > k) Q2.emplace(Q.top()), Q.pop();
}else {
if(Q.size() >= k) {
printf("%lld\n", Q.top());
Q.pop();
if(!Q2.empty()) {
Q.emplace(Q2.top()); Q2.pop();
}
}
else puts("-1");
}
}
return 0;
}