結果

問題 No.649 ここでちょっとQK!
ユーザー toyamatoyama
提出日時 2019-09-05 22:25:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 299 ms / 3,000 ms
コード長 1,207 bytes
コンパイル時間 800 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 5,792 KB
最終ジャッジ日時 2023-09-04 05:55:32
合計ジャッジ時間 7,389 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 299 ms
4,376 KB
testcase_04 AC 175 ms
5,656 KB
testcase_05 AC 172 ms
5,792 KB
testcase_06 AC 169 ms
5,388 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 96 ms
4,376 KB
testcase_13 AC 95 ms
4,380 KB
testcase_14 AC 92 ms
4,428 KB
testcase_15 AC 99 ms
4,412 KB
testcase_16 AC 92 ms
4,380 KB
testcase_17 AC 108 ms
4,552 KB
testcase_18 AC 117 ms
4,416 KB
testcase_19 AC 128 ms
4,480 KB
testcase_20 AC 137 ms
4,400 KB
testcase_21 AC 149 ms
4,848 KB
testcase_22 AC 160 ms
4,812 KB
testcase_23 AC 170 ms
4,556 KB
testcase_24 AC 181 ms
4,776 KB
testcase_25 AC 191 ms
4,784 KB
testcase_26 AC 200 ms
4,636 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 65 ms
4,376 KB
testcase_31 AC 63 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

MaxHeap<llong> find_Kth;
MinHeap<llong> others;
llong Q, K;
llong com, v;

int main() {

    cin >> Q >> K;


    while(Q--) {
        cin >> com;

        if (com == 1) {
            cin >> v;

            find_Kth.push(v);

            if (find_Kth.size() > K) {
                others.push(find_Kth.top());
                find_Kth.pop();
            }
        }
        else if (com == 2) {
            if (find_Kth.size() >= K) {
                printf("%lld\n", find_Kth.top());

                find_Kth.pop();

                if (!others.empty()) {
                    find_Kth.push(others.top());
                    others.pop();
                }
            }
            else {
                printf("%lld\n", -1ll);
            }
        }
    }

    return 0;
}
0