//summation segment treeletmut seg = SegSum::new(0, m);//range: [0,m), subsequent operations have to be within this rangelet delta :T = ...//T: Add<Output=T> + Mul<i64, Output<T>> + Clone + Default + Debugseg.add(a, b,&delta);//add delta to range [a,b)
seg.update(a, b,&val);//set range [a,b) to val
...let v :T = seg.query_range(i, j);//query sum in range [i,j)//max segment treeletmut seg = SegMax::new(0, m);//range: [0,m), subsequent operations have to be within this rangelet delta :T = ...//T: Add<Output=T> + Ord + Debug + Clone + Min//eg: implMinfori64{fn min() -> i64{
i64::MIN}}
seg.add(a, b,&delta);//add delta to range [a,b)
seg.update(a, b,&val);//set range [a,b) to max(val,element[i]) for i in [a,b)
...let v :T = seg.query_range(i, j);//query max in range [i,j)
red black tree
letmut t : treez::rb::TreeRb<isize,isize> = treez::rb::TreeRb::new();for i in0..nums.len(){let r = nums[i];
t.insert( r, i asisize);}for i in0..nums.len(){let r = nums[i];let v = t.remove(&r ).expect("remove unsuccessful");}
same logic as C++ lower/upper_bound; requires item type to have cmp::Ord trait
letmut arr = ...arr.sort();let val = ...let idx = bound::upper_bound(&arr[..],&val);//idx in [0, arr.size]letmut arr = ...arr.sort();let val = ...let idx = bound::lower_bound(&arr[..],&val);
strongly connected components
let num_nodes = 4usize;//nodes assumed to be contiguous in range [0,num_nodes)let rel = vec![(0, 1), (1, 2), (2, 0), (1, 3)];//edgeslet out = compute(num_nodes,&rel[..]);