結果

問題 No.649 ここでちょっとQK!
ユーザー lorent_kyopro
提出日時 2020-12-20 23:27:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 739 ms / 3,000 ms
コード長 755 bytes
コンパイル時間 3,043 ms
コンパイル使用メモリ 223,096 KB
最終ジャッジ日時 2025-01-17 05:07:47
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    int q, k;
    cin >> q >> k;
    ordered_set<pair<long long, int>> s;
    int id = 0;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            long long v;
            cin >> v;
            s.insert({v, id++});
        } else {
            if ((int)s.size() < k) {
                cout << -1 << '\n';
            } else {
                auto it = s.find_by_order(k - 1);
                cout << it->first << '\n';
                s.erase(it);
            }
        }
    }
}
0