pub struct BinaryIndexedTree2D<M>where
M: Monoid,{ /* private fields */ }
Implementations§
Source§impl<M> BinaryIndexedTree2D<M>where
M: Monoid,
impl<M> BinaryIndexedTree2D<M>where
M: Monoid,
pub fn new(h: usize, w: usize) -> Self
Sourcepub fn accumulate0(&self, i: usize, j: usize) -> M::T
pub fn accumulate0(&self, i: usize, j: usize) -> M::T
fold [0, i) x [0, j)
Examples found in repository?
crates/competitive/src/data_structure/binary_indexed_tree_2d.rs (line 67)
66 pub fn accumulate(&self, i: usize, j: usize) -> M::T {
67 self.accumulate0(i + 1, j + 1)
68 }
69 #[inline]
70 pub fn update(&mut self, i: usize, j: usize, x: M::T) {
71 let mut a = i + 1;
72 while a <= self.h {
73 let mut b = j + 1;
74 while b <= self.w {
75 self.bit[a][b] = M::operate(&self.bit[a][b], &x);
76 b += b & (!b + 1);
77 }
78 a += a & (!a + 1);
79 }
80 }
81}
82
83impl<G> BinaryIndexedTree2D<G>
84where
85 G: Group,
86{
87 #[inline]
88 /// 0-indexed [i1, i2) x [j1, j2)
89 pub fn fold(&self, i1: usize, j1: usize, i2: usize, j2: usize) -> G::T {
90 let mut res = G::unit();
91 res = G::operate(&res, &self.accumulate0(i1, j1));
92 res = G::rinv_operate(&res, &self.accumulate0(i1, j2));
93 res = G::rinv_operate(&res, &self.accumulate0(i2, j1));
94 res = G::operate(&res, &self.accumulate0(i2, j2));
95 res
96 }
Sourcepub fn accumulate(&self, i: usize, j: usize) -> M::T
pub fn accumulate(&self, i: usize, j: usize) -> M::T
fold [0, i] x [0, j]
Source§impl<G> BinaryIndexedTree2D<G>where
G: Group,
impl<G> BinaryIndexedTree2D<G>where
G: Group,
Trait Implementations§
Source§impl<M> Clone for BinaryIndexedTree2D<M>where
M: Monoid,
impl<M> Clone for BinaryIndexedTree2D<M>where
M: Monoid,
Auto Trait Implementations§
impl<M> Freeze for BinaryIndexedTree2D<M>
impl<M> RefUnwindSafe for BinaryIndexedTree2D<M>
impl<M> Send for BinaryIndexedTree2D<M>
impl<M> Sync for BinaryIndexedTree2D<M>
impl<M> Unpin for BinaryIndexedTree2D<M>
impl<M> UnwindSafe for BinaryIndexedTree2D<M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more