結果

問題 No.674 n連勤
ユーザー te-shte-sh
提出日時 2018-04-16 14:22:11
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 775 bytes
コンパイル時間 1,874 ms
コンパイル使用メモリ 156,268 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-13 00:28:17
合計ジャッジ時間 3,048 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 11
権限があれば一括ダウンロードができます

ソースコード

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, u = pr.b < a ? p : P(pr.a, max(pr.b, b));
    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