結果

問題 No.649 ここでちょっとQK!
ユーザー arukukaarukuka
提出日時 2018-02-11 15:08:10
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 1,214 bytes
コンパイル時間 1,540 ms
コンパイル使用メモリ 154,900 KB
実行使用メモリ 25,712 KB
最終ジャッジ日時 2023-09-03 18:44:24
合計ジャッジ時間 7,838 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 120 ms
4,376 KB
testcase_04 AC 211 ms
25,700 KB
testcase_05 AC 220 ms
25,676 KB
testcase_06 AC 204 ms
25,712 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
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!ulong);
    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.walkLength;
        if (r > k) {
          right = mid;
        } else {
          left = mid;
        }
      }
      auto res = tree.lowerBound(left + 1);
      if (res.walkLength < k) {
        auto trg = tree.upperBound(left).front;
        writeln =  trg;
        tree.removeKey = trg;
      } else {
        auto trg = res.back;
        writeln = trg;
        tree.removeKey = trg;
      }
    }
  }
}
0