結果

問題 No.649 ここでちょっとQK!
ユーザー te-shte-sh
提出日時 2018-04-19 11:36:43
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 248 ms / 3,000 ms
コード長 1,023 bytes
コンパイル時間 1,441 ms
コンパイル使用メモリ 153,948 KB
実行使用メモリ 19,332 KB
最終ジャッジ日時 2023-09-03 19:48:50
合計ジャッジ時間 6,952 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 95 ms
4,380 KB
testcase_04 AC 194 ms
19,332 KB
testcase_05 AC 149 ms
15,372 KB
testcase_06 AC 185 ms
16,480 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 96 ms
8,000 KB
testcase_13 AC 95 ms
7,924 KB
testcase_14 AC 93 ms
7,924 KB
testcase_15 AC 101 ms
8,432 KB
testcase_16 AC 97 ms
8,756 KB
testcase_17 AC 117 ms
11,060 KB
testcase_18 AC 128 ms
11,344 KB
testcase_19 AC 140 ms
13,100 KB
testcase_20 AC 157 ms
14,172 KB
testcase_21 AC 169 ms
14,160 KB
testcase_22 AC 180 ms
15,164 KB
testcase_23 AC 210 ms
15,364 KB
testcase_24 AC 229 ms
15,488 KB
testcase_25 AC 233 ms
15,352 KB
testcase_26 AC 248 ms
15,444 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,388 KB
testcase_30 AC 81 ms
7,900 KB
testcase_31 AC 88 ms
8,408 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,384 KB
testcase_34 AC 1 ms
4,384 KB
testcase_35 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}

void main()
{
  int q, k; readV(q, k);

  auto rb1 = redBlackTree!("a>b", true, long)(), rb2 = redBlackTree!("a<b", true, long)();
  foreach (_; 0..q) {
    auto rd = readln.splitter;
    switch (rd.front) {
    case "1":
      rd.popFront;
      auto v = rd.front.to!long;
      if (rb1.length < k) {
        rb1.insert(v);
      } else if (rb1.front < v) {
        rb2.insert(v);
      } else {
        auto u = rb1.front; rb1.removeFront;
        rb1.insert(v);
        rb2.insert(u);
      }
      break;
    case "2":
      if (rb1.length < k) {
        writeln(-1);
      } else {
        writeln(rb1.front);
        rb1.removeFront;
        if (!rb2.empty) {
          auto u = rb2.front; rb2.removeFront;
          rb1.insert(u);
        }
      }
      break;
    default:
      assert(0);
    }
  }
}
0