結果

問題 No.649 ここでちょっとQK!
ユーザー beetbeet
提出日時 2018-02-09 22:31:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 356 ms / 3,000 ms
コード長 870 bytes
コンパイル時間 2,657 ms
コンパイル使用メモリ 188,504 KB
実行使用メモリ 15,872 KB
最終ジャッジ日時 2024-04-17 04:53:31
合計ジャッジ時間 8,989 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 297 ms
5,376 KB
testcase_04 AC 294 ms
15,872 KB
testcase_05 AC 291 ms
15,872 KB
testcase_06 AC 301 ms
15,872 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 147 ms
8,448 KB
testcase_13 AC 148 ms
8,320 KB
testcase_14 AC 147 ms
8,320 KB
testcase_15 AC 154 ms
8,448 KB
testcase_16 AC 152 ms
8,960 KB
testcase_17 AC 176 ms
9,088 KB
testcase_18 AC 190 ms
9,728 KB
testcase_19 AC 213 ms
10,240 KB
testcase_20 AC 233 ms
10,752 KB
testcase_21 AC 254 ms
11,264 KB
testcase_22 AC 270 ms
11,904 KB
testcase_23 AC 290 ms
12,160 KB
testcase_24 AC 316 ms
12,800 KB
testcase_25 AC 329 ms
13,184 KB
testcase_26 AC 356 ms
13,696 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 114 ms
8,320 KB
testcase_31 AC 116 ms
8,704 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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