Struct BinaryIndexedTree2D

Source
pub struct BinaryIndexedTree2D<M>
where M: Monoid,
{ /* private fields */ }

Implementations§

Source§

impl<M> BinaryIndexedTree2D<M>
where M: Monoid,

Source

pub fn new(h: usize, w: usize) -> Self

Source

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    }
Source

pub fn accumulate(&self, i: usize, j: usize) -> M::T

fold [0, i] x [0, j]

Source

pub fn update(&mut self, i: usize, j: usize, x: M::T)

Examples found in repository?
crates/competitive/src/data_structure/binary_indexed_tree_2d.rs (line 105)
102    pub fn set(&mut self, i: usize, j: usize, x: G::T) {
103        let y = G::inverse(&self.get(i, j));
104        let z = G::operate(&y, &x);
105        self.update(i, j, z);
106    }
Source§

impl<G> BinaryIndexedTree2D<G>
where G: Group,

Source

pub fn fold(&self, i1: usize, j1: usize, i2: usize, j2: usize) -> G::T

0-indexed [i1, i2) x [j1, j2)

Examples found in repository?
crates/competitive/src/data_structure/binary_indexed_tree_2d.rs (line 99)
98    pub fn get(&self, i: usize, j: usize) -> G::T {
99        self.fold(i, j, i + 1, j + 1)
100    }
Source

pub fn get(&self, i: usize, j: usize) -> G::T

Examples found in repository?
crates/competitive/src/data_structure/binary_indexed_tree_2d.rs (line 103)
102    pub fn set(&mut self, i: usize, j: usize, x: G::T) {
103        let y = G::inverse(&self.get(i, j));
104        let z = G::operate(&y, &x);
105        self.update(i, j, z);
106    }
Source

pub fn set(&mut self, i: usize, j: usize, x: G::T)

Trait Implementations§

Source§

impl<M> Clone for BinaryIndexedTree2D<M>
where M: Monoid,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<M> Debug for BinaryIndexedTree2D<M>
where M: Monoid, M::T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<M> Freeze for BinaryIndexedTree2D<M>

§

impl<M> RefUnwindSafe for BinaryIndexedTree2D<M>
where <M as Magma>::T: RefUnwindSafe,

§

impl<M> Send for BinaryIndexedTree2D<M>
where <M as Magma>::T: Send,

§

impl<M> Sync for BinaryIndexedTree2D<M>
where <M as Magma>::T: Sync,

§

impl<M> Unpin for BinaryIndexedTree2D<M>
where <M as Magma>::T: Unpin,

§

impl<M> UnwindSafe for BinaryIndexedTree2D<M>
where <M as Magma>::T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.