結果

問題 No.649 ここでちょっとQK!
コンテスト
ユーザー ei1333333
提出日時 2018-02-09 22:36:57
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 126 ms / 3,000 ms
コード長 679 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,441 ms
コンパイル使用メモリ 258,844 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2026-06-06 21:42:25
合計ジャッジ時間 5,860 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

using namespace __gnu_pbds;

using namespace std;

using int64 = long long;

tree< pair< int64, int >, null_type, less< pair< int64, int > >, rb_tree_tag, tree_order_statistics_node_update > ts;

int main()
{
  int Q, K;
  scanf("%d %d", &Q, &K);
  --K;
  int ptr = 0;
  while(Q--) {
    int t;
    scanf("%d", &t);
    if(t == 1) {
      int64 x;
      scanf("%lld", &x);
      ts.insert(make_pair(x, ptr++));
    } else {
      if((int) ts.size() - 1 >= K) {
        auto p = ts.find_by_order(K);
        printf("%lld\n", p->first);
        ts.erase(p);
      } else {
        puts("-1");
      }
    }
  }

}

0