結果

問題 No.649 ここでちょっとQK!
ユーザー beet
提出日時 2018-02-09 22:31:44
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 296 ms / 3,000 ms
コード長 870 bytes
コンパイル時間 2,605 ms
コンパイル使用メモリ 189,372 KB
実行使用メモリ 16,000 KB
最終ジャッジ日時 2024-10-08 15:48:44
合計ジャッジ時間 8,763 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#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;
template <typename T>
using gtree = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
// usage:
// find_by_order(Int k): return the iterator of k-th smallest element (0-indexed)
// order_of_key(T key):  return the index of key in tree

//INSERT ABOVE HERE
signed main(){
  Int q,k;
  cin>>q>>k;
  using P = pair<Int,Int>;
  gtree<P> g;
  for(Int i=0;i<q;i++){
    Int t;
    cin>>t;
    if(t==1){
      Int x;
      cin>>x;
      g.insert(P(x,i));
    }
    if(t==2){
      if((Int)g.size()<k){
	cout<<-1<<endl;
	continue;
      }
      P v=*g.find_by_order(k-1);
      cout<<v.first<<endl;
      g.erase(v);
    }
  }
  
  return 0;
}
0