結果

問題 No.674 n連勤
ユーザー nebukuro09nebukuro09
提出日時 2018-04-13 23:56:02
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,134 bytes
コンパイル時間 1,553 ms
コンパイル使用メモリ 186,828 KB
実行使用メモリ 7,104 KB
最終ジャッジ日時 2023-09-03 19:28:03
合計ジャッジ時間 3,070 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 37 ms
4,376 KB
testcase_14 AC 38 ms
4,380 KB
testcase_15 AC 36 ms
4,376 KB
testcase_16 AC 56 ms
6,548 KB
testcase_17 AC 56 ms
7,104 KB
testcase_18 AC 52 ms
4,376 KB
testcase_19 AC 39 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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+1, b));
        if (!lb.empty && lb.back[1] >= a-1) {
            a = min(a, lb.back[0]);
            b = max(b, lb.back[1]);
            rbt.removeKey(lb.back);
        }

        auto ub = rbt.upperBound(tuple(a, b));
        Tuple!(long, long)[] to_remove;

        foreach (x; ub) {
            if (x[0] > b + 1) break;
            a = min(a, x[0]);
            b = max(b, x[1]);
            to_remove ~= x;
        }

        foreach (x; to_remove) {
            rbt.removeKey(x);
        }

        ans = max(ans, b - a + 1);
        ans.writeln;
        rbt.insert(tuple(a, b));
    }
}
0