結果

問題 No.649 ここでちょっとQK!
ユーザー totori_nyaatotori_nyaa
提出日時 2019-11-28 01:57:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 3,000 ms
コード長 1,172 bytes
コンパイル時間 1,389 ms
コンパイル使用メモリ 172,208 KB
実行使用メモリ 5,940 KB
最終ジャッジ日時 2024-04-27 17:50:11
合計ジャッジ時間 3,964 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 24 ms
5,376 KB
testcase_04 AC 58 ms
5,940 KB
testcase_05 AC 44 ms
5,876 KB
testcase_06 AC 47 ms
5,604 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 25 ms
5,376 KB
testcase_13 AC 23 ms
5,376 KB
testcase_14 AC 24 ms
5,376 KB
testcase_15 AC 27 ms
5,376 KB
testcase_16 AC 25 ms
5,376 KB
testcase_17 AC 30 ms
5,376 KB
testcase_18 AC 33 ms
5,376 KB
testcase_19 AC 35 ms
5,376 KB
testcase_20 AC 39 ms
5,376 KB
testcase_21 AC 43 ms
5,376 KB
testcase_22 AC 43 ms
5,376 KB
testcase_23 AC 49 ms
5,376 KB
testcase_24 AC 49 ms
5,376 KB
testcase_25 AC 53 ms
5,376 KB
testcase_26 AC 54 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 18 ms
5,376 KB
testcase_31 AC 20 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    
    ll q,k;
    cin>>q>>k;
    ll ans=-1;
    priority_queue<ll,vector<ll>> que;
    priority_queue<ll,vector<ll>,greater<ll>> gre;
    while(q--){
        ll t;
        cin>>t;
        if(t==1){
            ll v;
            cin>>v;
            if(que.size()==k){
                if(ans < v) gre.push(v);
                else {
                    que.push(v);
                    gre.push(que.top());
                    que.pop();
                    ans = que.top();
                }
            }
            else{
                que.push(v);
                if(que.size()==k){
                    ans = que.top();
                }
            }
        }
        if(t==2){
            cout << ans << "\n";
            if(que.size()==k){
                que.pop();
                ans = -1;
                if(gre.size()){
                    ans = gre.top();
                    que.push(ans);
                    gre.pop();
                }
            }
        }
    }

    
}
0