提出 #72163429


ソースコード 拡げる

#![allow(unused)]

use std::collections::BTreeSet;

use proconio::{input, marker::Usize1};

fn main() {
    input! {
        n: usize,
        q: usize,
        lr: [(usize, usize); q],
    }

    let mut ans = vec![];
    let mut segs = BTreeSet::new();
    let mut total = 0; // total length of the union

    for (l, r) in lr {
        let mut new_l = l;
        let mut new_r = r;
        while let Some(&(b, a)) = segs.range((new_l, 0)..).next() {
            if new_r < a {
                break;
            }
            segs.remove(&(b, a));
            total -= b - a + 1;
            new_l = new_l.min(a);
            new_r = new_r.max(b);
        }

        segs.insert((new_r, new_l));
        total += new_r - new_l + 1;

        ans.push(n - total);
    }

    println!("{}", join(&ans, "\n"));
}

fn join<T: ToString>(arr: &[T], sep: &str) -> String {
    arr.iter()
        .map(|x| x.to_string())
        .collect::<Vec<String>>()
        .join(sep)
}

提出情報

提出日時
問題 E - Cover query
ユーザ amoshuangyc
言語 Rust (rustc 1.89.0)
得点 450
コード長 1015 Byte
結果 AC
実行時間 92 ms
メモリ 23704 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 2
AC × 42
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 1860 KiB
example_01.txt AC 1 ms 1976 KiB
hand_00.txt AC 62 ms 23704 KiB
hand_01.txt AC 63 ms 23588 KiB
hand_02.txt AC 34 ms 16380 KiB
hand_03.txt AC 33 ms 16300 KiB
hand_04.txt AC 68 ms 16308 KiB
hand_05.txt AC 63 ms 16396 KiB
hand_06.txt AC 56 ms 16076 KiB
hand_07.txt AC 31 ms 14864 KiB
hand_08.txt AC 28 ms 16268 KiB
hand_09.txt AC 35 ms 16580 KiB
hand_10.txt AC 27 ms 14664 KiB
hand_11.txt AC 27 ms 14964 KiB
random_00.txt AC 31 ms 15648 KiB
random_01.txt AC 31 ms 15688 KiB
random_02.txt AC 32 ms 15520 KiB
random_03.txt AC 32 ms 15360 KiB
random_04.txt AC 32 ms 15640 KiB
random_05.txt AC 92 ms 18324 KiB
random_06.txt AC 92 ms 18596 KiB
random_07.txt AC 92 ms 18536 KiB
random_08.txt AC 92 ms 18492 KiB
random_09.txt AC 91 ms 18476 KiB
random_10.txt AC 32 ms 16028 KiB
random_11.txt AC 33 ms 16144 KiB
random_12.txt AC 32 ms 16032 KiB
random_13.txt AC 32 ms 15788 KiB
random_14.txt AC 32 ms 15800 KiB
random_15.txt AC 33 ms 15656 KiB
random_16.txt AC 34 ms 15884 KiB
random_17.txt AC 33 ms 15660 KiB
random_18.txt AC 34 ms 16160 KiB
random_19.txt AC 34 ms 15800 KiB
random_20.txt AC 92 ms 16628 KiB
random_21.txt AC 91 ms 16752 KiB
random_22.txt AC 92 ms 16604 KiB
random_23.txt AC 91 ms 16872 KiB
random_24.txt AC 91 ms 16692 KiB
random_25.txt AC 34 ms 15576 KiB
random_26.txt AC 33 ms 15588 KiB
random_27.txt AC 33 ms 15604 KiB