結果

問題 No.1000 Point Add and Array Add
ユーザー phsplsphspls
提出日時 2020-02-28 22:46:05
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,833 bytes
コンパイル時間 3,916 ms
コンパイル使用メモリ 181,396 KB
実行使用メモリ 14,596 KB
最終ジャッジ日時 2024-04-21 19:55:07
合計ジャッジ時間 8,315 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
12,900 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashMap;

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: usize = nq[0];
    let q: usize = nq[1];
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut b: Vec<isize> = vec![0; n+2];
    //increment val and total val
    let mut idx2inc: HashMap<usize, (usize, usize)> = HashMap::new();
    let mut result: Vec<usize> = vec![0; n];
    for _ in 0..q {
        let mut cxy = String::new();
        std::io::stdin().read_line(&mut cxy).ok();
        let mut cxy = cxy.trim().split_whitespace();
        let c: &str = cxy.next().unwrap();
        let x: usize = cxy.next().unwrap().parse().unwrap();
        let y: usize = cxy.next().unwrap().parse().unwrap();
        match c {
            "A" => {
                if let Some(r) = idx2inc.get_mut(&(x-1)) { 
                    *r = (r.0 + y, r.1);
                } else {
                    idx2inc.insert(x-1, (y, 0));
                }
            },
            "B" => {
                b[x] += 1;
                b[y+1] -= 1;
                for pair in idx2inc.iter_mut() {
                    if x <= *pair.0 && *pair.0 < y {
                        *pair.1 = ((pair.1).0, (pair.1).0 + (pair.1).1);
                    }
                }
            },
            _ => {}
        }
    }
    for i in 0..n {
        b[i+1] += b[i];
        result[i] += b[i+1] as usize * a[i];
        if idx2inc.contains_key(&i) {
            result[i] += (idx2inc.get(&i).unwrap()).1;
        }
    }
    println!("{}", result.iter().map(|i| i.to_string()).collect::<Vec<String>>().join(" "));
}
0