Skip to main content

XorLinkedRootedTreeScanner

Struct XorLinkedRootedTreeScanner 

Source
pub struct XorLinkedRootedTreeScanner<U, T = (), P = NoParent, D = NoDfsPreorder, H = NoDepth, PE = NoParentEdge, EC = NoEdgeChild, X = NoXorBottomUpOrder, B = NoXorBottomUpOrder, E = NoEIndexed>
where U: Scan<Output = usize>, T: Scan,
{ n: usize, root: usize, _marker: PhantomData<fn() -> ((U, T), (P, D, H), (PE, EC), (X, B, E))>, }

Fields§

§n: usize§root: usize§_marker: PhantomData<fn() -> ((U, T), (P, D, H), (PE, EC), (X, B, E))>

Implementations§

Source§

impl<U, T> XorLinkedRootedTreeScanner<U, T>
where U: Scan<Output = usize>, T: Scan,

Source

pub fn new(n: usize, root: usize) -> Self

Examples found in repository?
crates/library_checker/src/tree/vertex_add_path_sum.rs (line 19)
16pub fn vertex_add_path_sum(reader: impl Read, writer: impl Write) {
17    prepare_io!(reader, writer);
18    sc!(n, q, mut a: [i64; n],
19        (tree, _): @XorLinkedRootedTreeScanner::<usize, ()>::new(n, 0)
20            .with_parent().with_dfs_preorder());
21    let lca = LowestCommonAncestor::from_dfs_preorder(tree.parents(), tree.dfs_order());
22    let mut values = vec![0; n + 1];
23    for (u, &x) in a.iter().enumerate() {
24        let range = tree.subtree_range(u);
25        values[range.start] += x;
26        values[range.end] -= x;
27    }
28    let mut bit = BinaryIndexedTree::<AdditiveOperation<_>>::from_slice(&values);
29    for _ in 0..q {
30        sc!(query: Query);
31        match query {
32            Query::Add { p, x } => {
33                a[p] += x;
34                let range = tree.subtree_range(p);
35                bit.update(range.start, x);
36                bit.update(range.end, -x);
37            }
38            Query::Sum { u, v } => {
39                let p = lca.lca(u, v);
40                pp!(
41                    a[p] + bit.accumulate(tree.dfs_index(u)) + bit.accumulate(tree.dfs_index(v))
42                        - 2 * bit.accumulate(tree.dfs_index(p))
43                );
44            }
45        }
46    }
47}
Source§

impl<U, T, P, D, H, PE, EC, X, B, E> XorLinkedRootedTreeScanner<U, T, P, D, H, PE, EC, X, B, E>
where U: Scan<Output = usize>, T: Scan,

Source

pub fn with_parent( self, ) -> XorLinkedRootedTreeScanner<U, T, RecordParent, D, H, PE, EC, X, B, E>

Examples found in repository?
crates/library_checker/src/tree/vertex_add_path_sum.rs (line 20)
16pub fn vertex_add_path_sum(reader: impl Read, writer: impl Write) {
17    prepare_io!(reader, writer);
18    sc!(n, q, mut a: [i64; n],
19        (tree, _): @XorLinkedRootedTreeScanner::<usize, ()>::new(n, 0)
20            .with_parent().with_dfs_preorder());
21    let lca = LowestCommonAncestor::from_dfs_preorder(tree.parents(), tree.dfs_order());
22    let mut values = vec![0; n + 1];
23    for (u, &x) in a.iter().enumerate() {
24        let range = tree.subtree_range(u);
25        values[range.start] += x;
26        values[range.end] -= x;
27    }
28    let mut bit = BinaryIndexedTree::<AdditiveOperation<_>>::from_slice(&values);
29    for _ in 0..q {
30        sc!(query: Query);
31        match query {
32            Query::Add { p, x } => {
33                a[p] += x;
34                let range = tree.subtree_range(p);
35                bit.update(range.start, x);
36                bit.update(range.end, -x);
37            }
38            Query::Sum { u, v } => {
39                let p = lca.lca(u, v);
40                pp!(
41                    a[p] + bit.accumulate(tree.dfs_index(u)) + bit.accumulate(tree.dfs_index(v))
42                        - 2 * bit.accumulate(tree.dfs_index(p))
43                );
44            }
45        }
46    }
47}
Source

pub fn with_dfs_preorder( self, ) -> XorLinkedRootedTreeScanner<U, T, P, RecordDfsPreorder, H, PE, EC, X, RecordXorBottomUpOrder, E>

Examples found in repository?
crates/library_checker/src/tree/vertex_add_path_sum.rs (line 20)
16pub fn vertex_add_path_sum(reader: impl Read, writer: impl Write) {
17    prepare_io!(reader, writer);
18    sc!(n, q, mut a: [i64; n],
19        (tree, _): @XorLinkedRootedTreeScanner::<usize, ()>::new(n, 0)
20            .with_parent().with_dfs_preorder());
21    let lca = LowestCommonAncestor::from_dfs_preorder(tree.parents(), tree.dfs_order());
22    let mut values = vec![0; n + 1];
23    for (u, &x) in a.iter().enumerate() {
24        let range = tree.subtree_range(u);
25        values[range.start] += x;
26        values[range.end] -= x;
27    }
28    let mut bit = BinaryIndexedTree::<AdditiveOperation<_>>::from_slice(&values);
29    for _ in 0..q {
30        sc!(query: Query);
31        match query {
32            Query::Add { p, x } => {
33                a[p] += x;
34                let range = tree.subtree_range(p);
35                bit.update(range.start, x);
36                bit.update(range.end, -x);
37            }
38            Query::Sum { u, v } => {
39                let p = lca.lca(u, v);
40                pp!(
41                    a[p] + bit.accumulate(tree.dfs_index(u)) + bit.accumulate(tree.dfs_index(v))
42                        - 2 * bit.accumulate(tree.dfs_index(p))
43                );
44            }
45        }
46    }
47}
Source

pub fn with_depth( self, ) -> XorLinkedRootedTreeScanner<U, T, P, D, RecordDepth, PE, EC, X, RecordXorBottomUpOrder, E>

Source

pub fn with_xor_bottom_up_order( self, ) -> XorLinkedRootedTreeScanner<U, T, P, D, H, PE, EC, RecordXorBottomUpOrder, RecordXorBottomUpOrder, E>

Source§

impl<U, T, P, D, H, X, B> XorLinkedRootedTreeScanner<U, T, P, D, H, NoParentEdge, NoEdgeChild, X, B, NoEIndexed>
where U: Scan<Output = usize>, T: Scan,

Source§

impl<U, T, P, D, H, PE, EC, X, B> XorLinkedRootedTreeScanner<U, T, P, D, H, PE, EC, X, B, EIndexed>
where U: Scan<Output = usize>, T: Scan,

Source

pub fn with_parent_edge( self, ) -> XorLinkedRootedTreeScanner<U, T, P, D, H, RecordParentEdge, EC, X, B, EIndexed>

Source

pub fn with_edge_child( self, ) -> XorLinkedRootedTreeScanner<U, T, P, D, H, PE, RecordEdgeChild, X, B, EIndexed>

Trait Implementations§

Source§

impl<U, T, P, D, H, X, B> MarkedScan for XorLinkedRootedTreeScanner<U, T, P, D, H, NoParentEdge, NoEdgeChild, X, B, NoEIndexed>

Source§

impl<U, T, P, D, H, PE, EC, X, B> MarkedScan for XorLinkedRootedTreeScanner<U, T, P, D, H, PE, EC, X, B, EIndexed>

Source§

type Output = (XorLinkedRootedTree<P, D, H, PE, EC, X>, Vec<<T as Scan>::Output>)

Source§

fn mscan<I: ScanSource>(self, iter: &mut I) -> Option<Self::Output>

Auto Trait Implementations§

§

impl<U, T, P, D, H, PE, EC, X, B, E> Freeze for XorLinkedRootedTreeScanner<U, T, P, D, H, PE, EC, X, B, E>

§

impl<U, T, P, D, H, PE, EC, X, B, E> RefUnwindSafe for XorLinkedRootedTreeScanner<U, T, P, D, H, PE, EC, X, B, E>

§

impl<U, T, P, D, H, PE, EC, X, B, E> Send for XorLinkedRootedTreeScanner<U, T, P, D, H, PE, EC, X, B, E>

§

impl<U, T, P, D, H, PE, EC, X, B, E> Sync for XorLinkedRootedTreeScanner<U, T, P, D, H, PE, EC, X, B, E>

§

impl<U, T, P, D, H, PE, EC, X, B, E> Unpin for XorLinkedRootedTreeScanner<U, T, P, D, H, PE, EC, X, B, E>

§

impl<U, T, P, D, H, PE, EC, X, B, E> UnsafeUnpin for XorLinkedRootedTreeScanner<U, T, P, D, H, PE, EC, X, B, E>

§

impl<U, T, P, D, H, PE, EC, X, B, E> UnwindSafe for XorLinkedRootedTreeScanner<U, T, P, D, H, PE, EC, X, B, E>

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> 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> ToArrayVecScalar for T

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.