結果

問題 No.649 ここでちょっとQK!
ユーザー ikdikd
提出日時 2018-02-12 17:36:22
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 323 ms / 3,000 ms
コード長 1,010 bytes
コンパイル時間 1,323 ms
コンパイル使用メモリ 153,456 KB
実行使用メモリ 26,052 KB
最終ジャッジ日時 2023-09-03 18:45:36
合計ジャッジ時間 7,548 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 160 ms
4,376 KB
testcase_04 AC 287 ms
25,980 KB
testcase_05 AC 241 ms
25,948 KB
testcase_06 AC 283 ms
26,052 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 146 ms
15,496 KB
testcase_13 AC 145 ms
15,412 KB
testcase_14 AC 142 ms
15,352 KB
testcase_15 AC 153 ms
15,432 KB
testcase_16 AC 149 ms
15,396 KB
testcase_17 AC 162 ms
15,392 KB
testcase_18 AC 183 ms
15,492 KB
testcase_19 AC 200 ms
15,432 KB
testcase_20 AC 223 ms
15,392 KB
testcase_21 AC 237 ms
15,436 KB
testcase_22 AC 255 ms
16,300 KB
testcase_23 AC 268 ms
15,352 KB
testcase_24 AC 283 ms
23,460 KB
testcase_25 AC 319 ms
25,996 KB
testcase_26 AC 323 ms
25,552 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 124 ms
15,176 KB
testcase_31 AC 131 ms
15,432 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.container;

  int q, k; rd(q, k);
  // auto qmax=new BinaryHeap!(Array!(long))(),
  //      qmin=new BinaryHeap!(Array!(long), "a>b")();
  auto qmax=new RedBlackTree!(long, "a>b", true),
       qmin=new RedBlackTree!(long, "a<b", true);
  while(q--){
    auto args=readln.split.to!(long[]);
    if(args[0]==1){
      auto v=args[1];
      if(qmax.length<k) qmax.insert(v);
      else if(qmax.front<v) qmin.insert(v);
      else{qmin.insert(qmax.front); qmax.removeFront; qmax.insert(v);}
    }else{
      if(qmax.length>=k){
        writeln(qmax.front);
        qmax.removeFront;
        if(qmax.length<k && qmin.length>0){
          qmax.insert(qmin.front);
          qmin.removeFront;
        }
      }else{
        writeln(-1);
      }
    }
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
0