use std::collections::HashMap; fn main() { let mut nq = String::new(); std::io::stdin().read_line(&mut nq).ok(); let nq: Vec = 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 = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut b: Vec = vec![0; n+2]; //increment val and total val let mut idx2inc: HashMap = HashMap::new(); let mut result: Vec = 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!("{:?}, {:?}", idx2inc, b); println!("{}", result.iter().map(|i| i.to_string()).collect::>().join(" ")); }