結果

問題 No.1338 Giant Class
ユーザー StrorkisStrorkis
提出日時 2021-01-15 22:05:19
言語 Rust
(1.77.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,643 bytes
コンパイル時間 1,639 ms
コンパイル使用メモリ 155,848 KB
実行使用メモリ 4,892 KB
最終ジャッジ日時 2023-08-17 17:14:00
合計ジャッジ時間 3,741 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 33 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 34 ms
4,376 KB
testcase_07 AC 50 ms
4,480 KB
testcase_08 AC 32 ms
4,380 KB
testcase_09 AC 31 ms
4,380 KB
testcase_10 AC 55 ms
4,836 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 35 ms
4,376 KB
testcase_13 AC 38 ms
4,376 KB
testcase_14 AC 10 ms
4,376 KB
testcase_15 AC 15 ms
4,376 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 38 ms
4,376 KB
testcase_18 AC 11 ms
4,380 KB
testcase_19 AC 18 ms
4,376 KB
testcase_20 AC 68 ms
4,824 KB
testcase_21 AC 68 ms
4,804 KB
testcase_22 AC 69 ms
4,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{Read, Write};

struct Scanner<R> { bytes: std::io::Bytes<R>, buf: Vec<u8> }
 
impl<R: Read> Scanner<R> {
    fn new(r: R) -> Scanner<R> {
        Scanner { bytes: r.bytes(), buf: Vec::new() }
    }
  
    fn next(&mut self) -> &str {
        self.buf = {
            self.bytes.by_ref().map(|b| b.unwrap())
                .skip_while(|b| b.is_ascii_whitespace())
                .take_while(|b| !b.is_ascii_whitespace())
                .collect::<Vec<_>>()
        };
        unsafe { std::str::from_utf8_unchecked(&self.buf) }
    }
}

macro_rules! scan {
    ($sc:expr, [$t:tt; $n:expr]) => (
        (0..$n).map(|_| scan!($sc, $t)).collect::<Vec<_>>()
    );
    ($sc:expr, ($($t:tt),*)) => (($(scan!($sc, $t)),*));
    ($sc:expr, Usize1) => (scan!($sc, usize) - 1);
    ($sc:expr, Bytes) => ($sc.next().bytes().collect::<Vec<_>>());
    ($sc:expr, Chars) => ($sc.next().chars().collect::<Vec<_>>());
    ($sc:expr, $t:ty) => ($sc.next().parse::<$t>().unwrap());
}

fn run<R: Read, W: Write>(mut sc: Scanner<R>, mut wr: W) {
    let (h, w, q) = scan!(sc, (usize, usize, usize));
    let mut map = std::collections::BTreeMap::new();
    let mut ans = h * w;
    for _ in 0..q {
        let (y, x) = scan!(sc, (Usize1, Usize1));
        let value = map.entry(x).or_insert(h);
        if &y < value {
            ans -= *value - y;
            *value = y;
        }
        writeln!(wr, "{}", ans).ok();
    }
}

fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let sc = Scanner::new(std::io::BufReader::new(stdin.lock()));
    let wr = std::io::BufWriter::new(stdout.lock());
    run(sc, wr);
}
0