結果

問題 No.649 ここでちょっとQK!
コンテスト
ユーザー kakira9618
提出日時 2018-02-06 00:49:40
言語 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  
実行時間 117 ms / 3,000 ms
コード長 1,076 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,521 ms
コンパイル使用メモリ 223,316 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2026-04-24 10:28:27
合計ジャッジ時間 4,694 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include "bits/stdc++.h"

using namespace std;

#define pb push_back
#define mp make_pair
constexpr int INF = 1 << 29;
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;

constexpr int dx[4] = {1, 0, -1, 0};
constexpr int dy[4] = {0, 1, 0, -1};

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
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;
    scanf("%d%d", &Q, &K);
    int cnt = 0;
    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