結果

問題 No.1673 Lamps on a line
ユーザー Masaki Kitaguchi
提出日時 2022-01-09 02:16:25
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 889 bytes
コンパイル時間 14,749 ms
コンパイル使用メモリ 401,536 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-14 10:09:49
合計ジャッジ時間 16,858 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut buf = String::new();
    let mut input = {
        use std::io::Read;
        std::io::stdin().read_to_string(&mut buf).unwrap();
        buf.split_whitespace()
    };

    let n: usize = input.next().unwrap().parse().unwrap();
    let q: usize = input.next().unwrap().parse().unwrap();
    let lr: Vec<(usize, usize)> = (0..q)
        .map(|_| {
            (
                input.next().unwrap().parse().unwrap(),
                input.next().unwrap().parse().unwrap(),
            )
        })
        .collect();

    let mut lamps = vec![0; n];
    let mut count = 0;
    for i in 0..q {
        for j in (lr[i].0 - 1)..=(lr[i].1 - 1) {
            match lamps[j] {
                0 => count += 1,
                1 => count -= 1,
                _ => unreachable!(),
            }
            lamps[j] ^= 1;
        }
        println!("{}", count);
    }
}
0