結果
問題 | No.1000 Point Add and Array Add |
ユーザー |
|
提出日時 | 2020-02-28 22:46:05 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,833 bytes |
コンパイル時間 | 15,394 ms |
コンパイル使用メモリ | 377,100 KB |
実行使用メモリ | 10,496 KB |
最終ジャッジ日時 | 2024-10-13 18:36:58 |
合計ジャッジ時間 | 19,796 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 1 WA * 13 TLE * 1 -- * 7 |
ソースコード
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(" ")); }