結果

問題 No.649 ここでちょっとQK!
ユーザー pekempey
提出日時 2018-02-09 22:32:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 182 ms / 3,000 ms
コード長 992 bytes
コンパイル時間 4,422 ms
コンパイル使用メモリ 123,364 KB
実行使用メモリ 16,256 KB
最終ジャッジ日時 2024-10-08 15:51:14
合計ジャッジ時間 7,002 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// find_by_order(int) -> iterator
// order_of_key(int) -> int

using namespace __gnu_pbds;

template<class T> using Set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class TKey, class TVal> using Map = tree<TKey, TVal, std::less<TKey>, rb_tree_tag, tree_order_statistics_node_update>;

using namespace std;

long long input() {
  long long t;
  scanf("%lld", &t);
  return t;
}

int main() {
  int q, K;
  cin >> q >> K;

  Set<pair<long long, int>> st;

  while (q--) {
    if (input() == 1) {
      st.insert({input(), q});
    } else {
      if (st.size() >= K) {
        auto it = st.find_by_order(K - 1);
        printf("%lld\n", it->first);
        st.erase(it);
      } else {
        puts("-1");
      }
    }
  }
}
0