結果

問題 No.1673 Lamps on a line
ユーザー phsplsphspls
提出日時 2022-10-20 21:23:50
言語 Rust
(1.77.0)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 850 bytes
コンパイル時間 1,038 ms
コンパイル使用メモリ 144,416 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 01:49:15
合計ジャッジ時間 4,189 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 72 ms
4,380 KB
testcase_03 AC 75 ms
4,376 KB
testcase_04 AC 127 ms
4,380 KB
testcase_05 AC 7 ms
4,380 KB
testcase_06 AC 107 ms
4,376 KB
testcase_07 AC 86 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 128 ms
4,376 KB
testcase_10 AC 130 ms
4,376 KB
testcase_11 AC 12 ms
4,380 KB
testcase_12 AC 147 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut nq = String::new();
    std::io::stdin().read_line(&mut nq).ok();
    let nq: Vec<usize> = nq.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nq[0];
    let q = nq[1];
    let pairs = (0..q).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
            (temp[0]-1, temp[1])
        })
        .collect::<Vec<_>>();

    let mut lights = vec![false; n];
    let mut cnt = 0usize;
    for &(l, r) in pairs.iter() {
        for i in l..r {
            if lights[i] {
                cnt -= 1;
            } else {
                cnt += 1;
            }
            lights[i] = !lights[i];
        }
        println!("{}", cnt);
    }
}
0