結果

問題 No.674 n連勤
ユーザー te-shte-sh
提出日時 2018-04-16 14:26:52
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 852 bytes
コンパイル時間 1,517 ms
コンパイル使用メモリ 155,204 KB
実行使用メモリ 6,580 KB
最終ジャッジ日時 2023-09-03 19:29:55
合計ジャッジ時間 2,857 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 32 ms
4,384 KB
testcase_14 AC 28 ms
4,380 KB
testcase_15 AC 26 ms
4,380 KB
testcase_16 AC 39 ms
4,784 KB
testcase_17 AC 38 ms
6,580 KB
testcase_18 AC 37 ms
4,512 KB
testcase_19 AC 27 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()
{
  long d; int q; readV(d, q);

  struct P { long a, b; }
  auto inf = 2*10L^^18, m = 0L, rbt = redBlackTree!"a.a<b.a"([P(-inf, -inf), P(inf, inf)]);

  foreach (_; 0..q) {
    long a, b; readV(a, b); ++b;
    auto p = P(a, b), pr = rbt.lowerBound(p).back;
    P u;
    if (pr.b < a) {
      u = p;
    } else {
      u = P(pr.a, max(pr.b, b));
      rbt.removeKey(pr);
    }
    P[] rm;
    foreach (po; rbt.upperBound(P(a-1, b))) {
      if (po.a > u.b) break;
      rm ~= po;
      u = P(u.a, max(u.b, po.b));
    }
    foreach (rmi; rm) rbt.removeKey(rmi);
    m = max(m, u.b-u.a);
    rbt.insert(u);
    writeln(m);
  }
}
0