結果
| 問題 |
No.674 n連勤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-04-16 14:26:52 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 2,000 ms |
| コード長 | 852 bytes |
| コンパイル時間 | 1,641 ms |
| コンパイル使用メモリ | 157,620 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-13 00:28:24 |
| 合計ジャッジ時間 | 2,550 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
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);
}
}