結果

問題 No.649 ここでちょっとQK!
コンテスト
ユーザー V_Melville
提出日時 2026-10-20 22:27:49
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 137 ms / 3,000 ms
+ 510µs
コード長 856 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,747 ms
コンパイル使用メモリ 350,940 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2026-10-20 22:28:45
合計ジャッジ時間 9,721 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/extc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using P = pair<ll, int>;

template<class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    cin.tie(nullptr) -> sync_with_stdio(false);
    
    int q, k;
    cin >> q >> k;
    
    Tree<P> t;
    int cnt = 0;
    rep(qi, q) {
        int type;
        cin >> type;
        if (type == 1) {
            ll v;
            cin >> v;
            t.insert(P(v, cnt++));
        }
        else {
            if (t.size() < k) {
                puts("-1");
            }
            else {
                auto it = t.find_by_order(k-1);
                printf("%lld\n", *it);
                t.erase(it);
            }
        }
    }
    
    return 0;
}
0