結果

問題 No.649 ここでちょっとQK!
コンテスト
ユーザー kakira9618
提出日時 2018-02-06 00:52:03
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 129 ms / 3,000 ms
コード長 837 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,403 ms
コンパイル使用メモリ 228,356 KB
実行使用メモリ 16,512 KB
最終ジャッジ日時 2026-04-24 23:56:44
合計ジャッジ時間 7,419 ms
ジャッジサーバーID
(参考情報)
judge4_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>

using namespace std;
using namespace __gnu_pbds;
using Node = pair<long long int, int>;
tree<Node, null_type, less<Node>, rb_tree_tag, tree_order_statistics_node_update> S;

int main() {
    int Q, K, cnt = 0;
    scanf("%d%d", &Q, &K);
    for(int i = 0; i < Q; i++) {
        int q; scanf("%d", &q);
        if (q == 1) {
            long long int v;
            scanf("%lld", &v);
            S.insert(make_pair(v, cnt++));
        } else {
            if (S.size() < K) {
                puts("-1");
            } else {
                auto it = S.find_by_order(K - 1);
                printf("%lld\n", *it);
                S.erase(it);
            }
        }
    }
    
    return 0;
}
0