結果

問題 No.674 n連勤
コンテスト
ユーザー nebukuro09
提出日時 2018-04-13 23:52:42
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
RE  
実行時間 -
コード長 1,019 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 919 ms
コンパイル使用メモリ 142,008 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-03-05 20:03:59
合計ジャッジ時間 2,674 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 RE * 1
other AC * 5 RE * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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));
        foreach (x; ub) {
            if (x[0] > b + 1) break;
            a = min(a, x[0]);
            b = max(b, x[1]);
            rbt.removeKey(x);
        }
        ans = max(ans, b - a + 1);
        ans.writeln;
        rbt.insert(tuple(a, b));
    }
}
0