結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 120 ms
4,376 KB
testcase_04 AC 246 ms
26,044 KB
testcase_05 AC 249 ms
25,988 KB
testcase_06 AC 234 ms
24,984 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 130 ms
15,460 KB
testcase_13 AC 127 ms
15,452 KB
testcase_14 AC 126 ms
15,452 KB
testcase_15 AC 135 ms
15,448 KB
testcase_16 AC 113 ms
14,884 KB
testcase_17 AC 147 ms
15,488 KB
testcase_18 AC 155 ms
15,412 KB
testcase_19 AC 177 ms
15,340 KB
testcase_20 AC 190 ms
15,380 KB
testcase_21 AC 214 ms
15,352 KB
testcase_22 AC 222 ms
17,948 KB
testcase_23 AC 240 ms
20,580 KB
testcase_24 AC 249 ms
23,744 KB
testcase_25 AC 272 ms
25,712 KB
testcase_26 AC 300 ms
25,976 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 113 ms
15,388 KB
testcase_31 AC 109 ms
15,192 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;

void main()
{
  auto val = readln.chomp.split.map!(to!int);
  int q = val.front;
  int k = val.back;
  alias TreeOne = RedBlackTree!(ulong, "a < b", true);
  TreeOne treeLeft = new TreeOne();
  TreeOne treeRight = new TreeOne();
  foreach (i; 0..q) {
    auto wal = readln.chomp.split.map!(to!ulong);
    if (wal.front == 1) {
      auto trg = wal.back;
      treeLeft.insert(trg);
      if (treeLeft.length > k) {
        auto dst = treeLeft.back;
        treeLeft.removeKey = dst;
        treeRight.insert(dst);
      }
    } else {
      auto l = treeLeft.length;
      if (l < k) {
        writeln = -1;
        continue;
      }
      auto v = treeLeft.back;
      treeLeft.removeKey = v;
      if (treeRight.length) {
        auto w = treeRight.front;
        treeRight.removeKey = w;
        treeLeft.insert(w);
      }
      v.writeln;
    }
  }
}
0