結果

問題 No.59 鉄道の旅
ユーザー te-shte-sh
提出日時 2017-05-08 14:17:25
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 968 bytes
コンパイル時間 834 ms
コンパイル使用メモリ 86,792 KB
実行使用メモリ 9,280 KB
最終ジャッジ日時 2023-09-03 13:10:39
合計ジャッジ時間 2,191 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,916 KB
testcase_01 AC 3 ms
6,760 KB
testcase_02 AC 3 ms
7,432 KB
testcase_03 AC 4 ms
6,484 KB
testcase_04 AC 32 ms
8,256 KB
testcase_05 WA -
testcase_06 AC 4 ms
8,004 KB
testcase_07 WA -
testcase_08 AC 6 ms
6,752 KB
testcase_09 AC 6 ms
6,700 KB
testcase_10 WA -
testcase_11 AC 5 ms
6,748 KB
testcase_12 AC 21 ms
7,484 KB
testcase_13 RE -
testcase_14 WA -
testcase_15 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

const auto maxW = 1_000_000;

void main()
{
  auto rd = readln.split, n = rd[0].to!size_t, k = rd[1].to!int;

  auto bt = BiTree!int(maxW);
  foreach (_; n.iota) {
    auto w = readln.chomp.to!int;
    if (w > 0) {
      if (bt[w..$] < k)
        bt[w] += 1;
    } else {
      w = -w;
      if (bt[w..w+1] > 0)
        bt[w] += -1;
    }
  }

  writeln(bt[0..$]);
}

struct BiTree(T)
{
  const size_t n;
  T[] buf;

  this(size_t n)
  {
    this.n = n;
    this.buf = new T[](n + 1);
  }

  void opIndexOpAssign(string op)(T val, size_t i)
    if (op == "+")
  {
    ++i;
    while (i <= n) {
      buf[i] += val;
      i += i & -i;
    }
  }

  pure size_t opDollar() { return n; }

  pure T opSlice(size_t r, size_t l) const
  {
    return get(l) - get(r);
  }

  pure T get(size_t i) const
  {
    auto s = T(0);
    while (i > 0) {
      s += buf[i];
      i -= i & -i;
    }
    return s;
  }
}
0