結果

問題 No.649 ここでちょっとQK!
ユーザー imulanimulan
提出日時 2018-03-14 00:58:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 3,000 ms
コード長 1,398 bytes
コンパイル時間 1,671 ms
コンパイル使用メモリ 170,596 KB
実行使用メモリ 5,656 KB
最終ジャッジ日時 2023-08-16 03:12:23
合計ジャッジ時間 7,306 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 31 ms
4,376 KB
testcase_04 AC 63 ms
5,656 KB
testcase_05 AC 53 ms
5,544 KB
testcase_06 AC 53 ms
5,424 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 29 ms
4,472 KB
testcase_13 AC 29 ms
4,376 KB
testcase_14 AC 27 ms
4,376 KB
testcase_15 AC 32 ms
4,376 KB
testcase_16 AC 31 ms
4,380 KB
testcase_17 AC 35 ms
4,380 KB
testcase_18 AC 39 ms
4,460 KB
testcase_19 AC 41 ms
4,384 KB
testcase_20 AC 45 ms
4,588 KB
testcase_21 AC 51 ms
4,692 KB
testcase_22 AC 53 ms
4,640 KB
testcase_23 AC 56 ms
4,608 KB
testcase_24 AC 60 ms
4,636 KB
testcase_25 AC 63 ms
4,728 KB
testcase_26 AC 64 ms
4,536 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 22 ms
4,380 KB
testcase_31 AC 24 ms
4,384 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int Q,K;
    scanf(" %d %d", &Q, &K);

    priority_queue<ll> small;
    priority_queue<ll, vector<ll>, greater<ll>> large;

    while(Q--){
        int q;
        scanf(" %d", &q);
        if(q==1){
            ll v;
            scanf(" %lld", &v);
            if(small.size()<K) small.push(v);
            else{
                if(small.top()>v){
                    large.push(small.top());
                    small.pop();
                    small.push(v);
                }
                else large.push(v);
            }
        }
        else{
            ll ans = -1;
            if(small.size() == K){
                ans = small.top();
                small.pop();
                if(!large.empty()){
                    small.push(large.top());
                    large.pop();
                }
            }
            printf("%lld\n", ans);
        }
    }

    return 0;
}
0