結果

問題 No.2306 [Cherry 5th Tune C] ウソツキタマシイ
ユーザー haihamabossuhaihamabossu
提出日時 2023-05-19 21:29:13
言語 Rust
(1.77.0)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 1,811 bytes
コンパイル時間 5,047 ms
コンパイル使用メモリ 149,064 KB
実行使用メモリ 8,408 KB
最終ジャッジ日時 2023-08-22 23:34:06
合計ジャッジ時間 10,419 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 105 ms
6,604 KB
testcase_08 AC 18 ms
4,804 KB
testcase_09 AC 59 ms
6,828 KB
testcase_10 AC 65 ms
4,384 KB
testcase_11 AC 69 ms
5,192 KB
testcase_12 AC 92 ms
7,784 KB
testcase_13 AC 60 ms
7,264 KB
testcase_14 AC 52 ms
5,592 KB
testcase_15 AC 130 ms
5,300 KB
testcase_16 AC 142 ms
4,384 KB
testcase_17 AC 168 ms
7,988 KB
testcase_18 AC 162 ms
7,992 KB
testcase_19 AC 162 ms
7,988 KB
testcase_20 AC 158 ms
7,980 KB
testcase_21 AC 163 ms
7,980 KB
testcase_22 AC 161 ms
7,988 KB
testcase_23 AC 159 ms
7,964 KB
testcase_24 AC 163 ms
7,908 KB
testcase_25 AC 159 ms
7,988 KB
testcase_26 AC 163 ms
7,980 KB
testcase_27 AC 156 ms
8,408 KB
testcase_28 AC 163 ms
8,408 KB
testcase_29 AC 142 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

pub mod scanner {

    pub struct Scanner {
        buf: Vec<String>,
    }

    impl Scanner {
        pub fn new() -> Self {
            Self { buf: vec![] }
        }

        pub fn new_from(source: &str) -> Self {
            let source = String::from(source);
            let buf = Self::split(source);
            Self { buf }
        }

        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            loop {
                if let Some(x) = self.buf.pop() {
                    return x.parse().ok().expect("");
                }
                let mut source = String::new();
                std::io::stdin().read_line(&mut source).expect("");
                self.buf = Self::split(source);
            }
        }

        fn split(source: String) -> Vec<String> {
            source
                .split_whitespace()
                .rev()
                .map(String::from)
                .collect::<Vec<_>>()
        }
    }
}

use crate::scanner::Scanner;

fn main() {
    let mut scanner = Scanner::new();
    let t: usize = 1;
    for _ in 0..t {
        solve(&mut scanner);
    }
}

fn solve(scanner: &mut Scanner) {
    let _n: usize = scanner.next();
    let m: usize = scanner.next();
    let mut now: usize = 0;
    let mut a: Vec<usize> = (0..m)
        .map(|_| {
            let x = scanner.next::<usize>();
            now += x * x;
            x
        })
        .collect();
    let q: usize = scanner.next();
    for _ in 0..q {
        let c: usize = scanner.next::<usize>() - 1;
        let k: usize = scanner.next::<usize>();
        let d: usize = scanner.next::<usize>() - 1;
        now -= a[c] * a[c];
        now -= a[d] * a[d];
        a[c] -= k;
        a[d] += k;
        now += a[c] * a[c];
        now += a[d] * a[d];
        println!("{}", now);
    }
}
0