#[allow(dead_code)] #[allow(unused_imports)] fn read() -> T { use std::io::*; let stdin = stdin(); let stdin = stdin.lock(); let token: String = stdin .bytes() .map(|c| c.expect("failed to read char") as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().expect("failed to parse token") } pub mod segment_tree {//基本的には整数型で使うことを想定しています(最悪C++に逃げましょう) use std::ops::*; fn e() -> T where T:Eq + Copy + Add + AddAssign + BitAnd + BitAndAssign + BitOr + BitOrAssign + BitXor + BitXorAssign + Mul + MulAssign + Identity, { T::identity() } fn op(x:T,y:T) -> T where T:Eq + Copy + Add + AddAssign + BitAnd + BitAndAssign + BitOr + BitOrAssign + BitXor + BitXorAssign + Mul + MulAssign, { x + y } pub trait Identity { fn identity() -> Self; } macro_rules! impl_identity{ ($($t:ty),*) => { $( impl Identity for $t { fn identity() -> Self { 0 } } )* }; } impl_identity!{i64,usize,u64,i32,u32,isize} #[derive(Debug)] pub struct SegmentTree { node:Vec, cnt:usize, sz:usize, } impl SegmentTree where T:Eq + Copy + Add + AddAssign + BitAnd + BitAndAssign + BitOr + BitOrAssign + BitXor + BitXorAssign + Mul + MulAssign + Identity, { pub fn new(_n:usize) -> Self{ let mut _cnt = 0; while (1usize << _cnt) < _n { _cnt += 1; } let size = 1 << _cnt; Self { sz:size, node:vec![e();size * 2], cnt:_cnt, } } pub fn set(&mut self,_i:usize,x:T) { let mut i = _i; i += self.sz; self.node[i] = x; for bit in 1..=self.cnt { self.update(i >> bit); } } pub fn get(&mut self,i:usize) -> T { self.node[i + self.sz] } pub fn prod(&mut self,_l:usize,_r:usize) -> T { let mut resl = e(); let mut l = _l + self.sz; let mut r = _r + self.sz; let mut resr = e(); while l < r { if l & 1 == 1 { resl = op(resl,self.node[l]); l += 1; } if r & 1 == 1 { r -= 1; resr = op(resr,self.node[r]); } l >>= 1; r >>= 1; } op(resl,resr) } pub fn update (&mut self,k:usize) { self.node[k] = op(self.node[2 * k],self.node[2 * k + 1]); } pub fn all_prod(&mut self) -> T{ self.node[1] } } } fn main(){ let n:usize = read(); let q:usize = read(); let mut seg_b = segment_tree::SegmentTree::::new(n); let mut seg_c = segment_tree::SegmentTree::::new(n + 1); let mut a:Vec = (0..n).map(|_| read()).collect(); let mut query:Vec<(char,usize,i64)> = (0..q).map(|i| (read() ,read() ,read())).collect(); query.reverse(); for i in 0..q { let (c,x,y) = query[i]; if c == 'A' { let v = seg_b.get(x - 1); seg_b.set(x - 1, v + y * seg_c.prod(0,x)); }else{ let v = seg_c.get(x - 1); let vv = seg_c.get(y as usize); seg_c.set(x - 1,v + 1); seg_c.set(y as usize,vv - 1); } } for i in 0..n { let v = seg_b.get(i); seg_b.set(i,v + a[i] * seg_c.prod(0,i + 1)); } for i in 0..n { print!("{} ", seg_b.get(i)); } println!(""); }