結果

問題 No.649 ここでちょっとQK!
ユーザー arukukaarukuka
提出日時 2018-02-10 00:14:28
言語 D
(dmd 2.106.1)
結果
RE  
実行時間 -
コード長 1,217 bytes
コンパイル時間 3,155 ms
コンパイル使用メモリ 153,084 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-09-03 18:41:29
合計ジャッジ時間 7,486 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 RE -
testcase_03 AC 123 ms
4,376 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 1 ms
4,376 KB
testcase_08 RE -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 9 ms
6,668 KB
testcase_30 TLE -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

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 tree = new TreeOne();
  foreach (i; 0..q) {
    auto wal = readln.chomp.split.map!(to!int);
    if (wal.front == 1) {
      auto trg = wal.back;
      tree.insert(trg);
    } else {
      auto l = tree.length;
      if (l < k) {
        writeln = -1;
        continue;
      }
      ulong left = tree.front;
      ulong right = tree.back + 1;
      while (right - left > 1) {
        ulong mid = (left + right) / 2;
        auto res = tree.lowerBound(mid + 1);
        auto r = res.array.length;
        if (r > k) {
          right = mid;
        } else {
          left = mid;
        }
      }
      auto res = tree.lowerBound(left + 1);
      if (res.array.length < k) {
        auto trg = tree.upperBound(left).front;
        writeln =  trg;
        tree.removeKey = trg;
      } else {
        auto trg = res.back;
        writeln = trg;
        tree.removeKey = trg;
      }
    }
  }
}

0