結果

問題 No.649 ここでちょっとQK!
ユーザー glretoglreto
提出日時 2020-10-08 13:57:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 263 ms / 3,000 ms
コード長 1,700 bytes
コンパイル時間 834 ms
コンパイル使用メモリ 98,716 KB
実行使用メモリ 5,636 KB
最終ジャッジ日時 2023-09-27 11:47:45
合計ジャッジ時間 5,394 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 263 ms
4,376 KB
testcase_04 AC 159 ms
5,636 KB
testcase_05 AC 146 ms
5,452 KB
testcase_06 AC 156 ms
5,360 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 84 ms
4,380 KB
testcase_13 AC 81 ms
4,384 KB
testcase_14 AC 80 ms
4,380 KB
testcase_15 AC 87 ms
4,384 KB
testcase_16 AC 88 ms
4,380 KB
testcase_17 AC 94 ms
4,380 KB
testcase_18 AC 107 ms
4,380 KB
testcase_19 AC 114 ms
4,376 KB
testcase_20 AC 123 ms
4,384 KB
testcase_21 AC 130 ms
4,500 KB
testcase_22 AC 143 ms
4,588 KB
testcase_23 AC 150 ms
4,500 KB
testcase_24 AC 160 ms
4,428 KB
testcase_25 AC 165 ms
4,392 KB
testcase_26 AC 177 ms
4,552 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 54 ms
4,376 KB
testcase_31 AC 57 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<sstream>
#include<cmath>
#include<functional>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int inf = 2e9; 
const int MOD = 1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(void) {
    int q, k, t; ll v; cin >> q >> k;
    priority_queue < ll, vector<ll>, greater<ll>> pq;
    priority_queue<ll> pp;
    rep(i, q) {
        cin >> t;
        if (t == 1) {
            cin >> v;
            if (pp.size() < k) pp.push(v);
            else {
                ll kth = pp.top();
                if (v < kth) {
                    pp.pop();
                    pp.push(v); pq.push(kth);
                }
                else pq.push(v);
            }
        }
        else {
            if (pp.size() < k)cout << -1 << endl;
            else {
                ll kth = pp.top();
                cout << kth << endl;
                pp.pop();
                if (!pq.empty()) {
                    kth = pq.top();
                    pq.pop(); pp.push(kth);
                }
            }
        }
    }
}
0