結果
| 問題 |
No.674 n連勤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-04-13 23:13:31 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,576 bytes |
| コンパイル時間 | 1,674 ms |
| コンパイル使用メモリ | 193,280 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-13 00:25:18 |
| 合計ジャッジ時間 | 3,214 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 WA * 3 RE * 2 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;
void main() {
immutable long MAX = 10L^18+10;
auto s = readln.split.map!(to!long);
auto D = s[0];
auto Q = s[1];
auto rbt = redBlackTree!(Tuple!(long, long))();
long ans = 0;
while (Q--) {
s = readln.split.map!(to!long);
auto a = s[0];
auto b = s[1];
auto lb = rbt.lowerBound(tuple(a, b));
if (!lb.empty && lb.back[0] == a) {
a = min(a, lb.back[0]);
b = max(b, lb.back[1]);
rbt.removeKey(lb.back);
lb = rbt.lowerBound(tuple(a, b));
}
auto ub = rbt.upperBound(tuple(a, b));
if (!ub.empty && ub.front[0] == a) {
a = min(a, ub.front[0]);
b = max(b, ub.front[1]);
rbt.removeKey(ub.front);
ub = rbt.lowerBound(tuple(a, b));
}
if (!lb.empty) {
auto left = lb.back;
if (a <= left[1] + 1) {
rbt.removeKey(left);
a = min(a, left[0]);
b = max(b, left[1]);
}
}
if (!ub.empty) {
auto right = ub.front;
if (b + 1 >= right[0]) {
rbt.removeKey(right);
a = min(a, right[0]);
b = max(b, right[1]);
}
}
ans = max(ans, b - a + 1);
ans.writeln;
rbt.insert(tuple(a, b));
}
}