pub struct ContourQueryRange {
comp_range: Vec<usize>,
info_indptr: Vec<usize>,
infos: Vec<ContourInfo>,
local_info: Vec<(usize, usize)>,
local_offsets: Vec<usize>,
local_masks: Vec<u32>,
}Fields§
§comp_range: Vec<usize>§info_indptr: Vec<usize>§infos: Vec<ContourInfo>§local_info: Vec<(usize, usize)>§local_offsets: Vec<usize>§local_masks: Vec<u32>Implementations§
Source§impl ContourQueryRange
impl ContourQueryRange
pub fn is_empty(&self) -> bool
Sourcepub fn component_sizes(&self) -> impl ExactSizeIterator<Item = usize> + '_
pub fn component_sizes(&self) -> impl ExactSizeIterator<Item = usize> + '_
Examples found in repository?
crates/library_checker/src/tree/vertex_get_range_contour_add_on_tree.rs (line 19)
14pub fn vertex_get_range_contour_add_on_tree(reader: impl Read, writer: impl Write) {
15 prepare_io!(reader, writer);
16 sc!(n, q, mut a: [i64; n], (graph, _): @TreeGraphScanner::<usize, ()>::new(n));
17 let cq = graph.contour_query_range();
18 let mut bits: Vec<BinaryIndexedTree<AdditiveOperation<_>>> = cq
19 .component_sizes()
20 .map(|n| BinaryIndexedTree::new(n + 1))
21 .collect();
22
23 for _ in 0..q {
24 sc!(query: Query);
25 match query {
26 Query::Add { v, l, r, x } => {
27 cq.for_each_contour_range(v, l, r, |c, start, end| {
28 bits[c].update(start, x);
29 bits[c].update(end, -x);
30 });
31 if l == 0 && 0 < r {
32 a[v] += x;
33 }
34 }
35 Query::Get { v } => {
36 let mut ans = a[v];
37 cq.for_each_index(v, |c, i| ans += bits[c].accumulate(i));
38 pp!(ans);
39 }
40 }
41 }
42}More examples
crates/library_checker/src/tree/vertex_add_range_contour_sum_on_tree.rs (line 18)
14pub fn vertex_add_range_contour_sum_on_tree(reader: impl Read, writer: impl Write) {
15 prepare_io!(reader, writer);
16 sc!(n, q, mut a: [i64; n], (graph, _): @TreeGraphScanner::<usize, ()>::new(n));
17 let cq = graph.contour_query_range();
18 let mut raw: Vec<_> = cq.component_sizes().map(|n| vec![0; n]).collect();
19 for (v, &x) in a.iter().enumerate() {
20 cq.for_each_index(v, |c, i| raw[c][i] += x);
21 }
22 let mut bits: Vec<BinaryIndexedTree<AdditiveOperation<_>>> = raw
23 .into_iter()
24 .map(|values| BinaryIndexedTree::from_slice(&values))
25 .collect();
26 for _ in 0..q {
27 sc!(query: Query);
28 match query {
29 Query::Add { p, x } => {
30 a[p] += x;
31 cq.for_each_index(p, |c, i| bits[c].update(i, x));
32 }
33 Query::Sum { v, l, r } => {
34 let mut ans = if l == 0 && 0 < r { a[v] } else { 0 };
35 cq.for_each_contour_range(v, l, r, |c, start, end| {
36 ans += bits[c].fold_abelian(start, end);
37 });
38 pp!(ans);
39 }
40 }
41 }
42}Sourcepub fn for_each_index(&self, v: usize, f: impl FnMut(usize, usize))
pub fn for_each_index(&self, v: usize, f: impl FnMut(usize, usize))
Calls f(component, index) for each position representing v.
Examples found in repository?
crates/library_checker/src/tree/vertex_get_range_contour_add_on_tree.rs (line 37)
14pub fn vertex_get_range_contour_add_on_tree(reader: impl Read, writer: impl Write) {
15 prepare_io!(reader, writer);
16 sc!(n, q, mut a: [i64; n], (graph, _): @TreeGraphScanner::<usize, ()>::new(n));
17 let cq = graph.contour_query_range();
18 let mut bits: Vec<BinaryIndexedTree<AdditiveOperation<_>>> = cq
19 .component_sizes()
20 .map(|n| BinaryIndexedTree::new(n + 1))
21 .collect();
22
23 for _ in 0..q {
24 sc!(query: Query);
25 match query {
26 Query::Add { v, l, r, x } => {
27 cq.for_each_contour_range(v, l, r, |c, start, end| {
28 bits[c].update(start, x);
29 bits[c].update(end, -x);
30 });
31 if l == 0 && 0 < r {
32 a[v] += x;
33 }
34 }
35 Query::Get { v } => {
36 let mut ans = a[v];
37 cq.for_each_index(v, |c, i| ans += bits[c].accumulate(i));
38 pp!(ans);
39 }
40 }
41 }
42}More examples
crates/library_checker/src/tree/vertex_add_range_contour_sum_on_tree.rs (line 20)
14pub fn vertex_add_range_contour_sum_on_tree(reader: impl Read, writer: impl Write) {
15 prepare_io!(reader, writer);
16 sc!(n, q, mut a: [i64; n], (graph, _): @TreeGraphScanner::<usize, ()>::new(n));
17 let cq = graph.contour_query_range();
18 let mut raw: Vec<_> = cq.component_sizes().map(|n| vec![0; n]).collect();
19 for (v, &x) in a.iter().enumerate() {
20 cq.for_each_index(v, |c, i| raw[c][i] += x);
21 }
22 let mut bits: Vec<BinaryIndexedTree<AdditiveOperation<_>>> = raw
23 .into_iter()
24 .map(|values| BinaryIndexedTree::from_slice(&values))
25 .collect();
26 for _ in 0..q {
27 sc!(query: Query);
28 match query {
29 Query::Add { p, x } => {
30 a[p] += x;
31 cq.for_each_index(p, |c, i| bits[c].update(i, x));
32 }
33 Query::Sum { v, l, r } => {
34 let mut ans = if l == 0 && 0 < r { a[v] } else { 0 };
35 cq.for_each_contour_range(v, l, r, |c, start, end| {
36 ans += bits[c].fold_abelian(start, end);
37 });
38 pp!(ans);
39 }
40 }
41 }
42}Sourcepub fn for_each_contour_range(
&self,
v: usize,
l: usize,
r: usize,
f: impl FnMut(usize, usize, usize),
)
pub fn for_each_contour_range( &self, v: usize, l: usize, r: usize, f: impl FnMut(usize, usize, usize), )
Calls f(component, start, end) for disjoint ranges at distances in l..r from v.
The ranges exclude v itself, even when l == 0.
Examples found in repository?
crates/library_checker/src/tree/vertex_get_range_contour_add_on_tree.rs (lines 27-30)
14pub fn vertex_get_range_contour_add_on_tree(reader: impl Read, writer: impl Write) {
15 prepare_io!(reader, writer);
16 sc!(n, q, mut a: [i64; n], (graph, _): @TreeGraphScanner::<usize, ()>::new(n));
17 let cq = graph.contour_query_range();
18 let mut bits: Vec<BinaryIndexedTree<AdditiveOperation<_>>> = cq
19 .component_sizes()
20 .map(|n| BinaryIndexedTree::new(n + 1))
21 .collect();
22
23 for _ in 0..q {
24 sc!(query: Query);
25 match query {
26 Query::Add { v, l, r, x } => {
27 cq.for_each_contour_range(v, l, r, |c, start, end| {
28 bits[c].update(start, x);
29 bits[c].update(end, -x);
30 });
31 if l == 0 && 0 < r {
32 a[v] += x;
33 }
34 }
35 Query::Get { v } => {
36 let mut ans = a[v];
37 cq.for_each_index(v, |c, i| ans += bits[c].accumulate(i));
38 pp!(ans);
39 }
40 }
41 }
42}More examples
crates/library_checker/src/tree/vertex_add_range_contour_sum_on_tree.rs (lines 35-37)
14pub fn vertex_add_range_contour_sum_on_tree(reader: impl Read, writer: impl Write) {
15 prepare_io!(reader, writer);
16 sc!(n, q, mut a: [i64; n], (graph, _): @TreeGraphScanner::<usize, ()>::new(n));
17 let cq = graph.contour_query_range();
18 let mut raw: Vec<_> = cq.component_sizes().map(|n| vec![0; n]).collect();
19 for (v, &x) in a.iter().enumerate() {
20 cq.for_each_index(v, |c, i| raw[c][i] += x);
21 }
22 let mut bits: Vec<BinaryIndexedTree<AdditiveOperation<_>>> = raw
23 .into_iter()
24 .map(|values| BinaryIndexedTree::from_slice(&values))
25 .collect();
26 for _ in 0..q {
27 sc!(query: Query);
28 match query {
29 Query::Add { p, x } => {
30 a[p] += x;
31 cq.for_each_index(p, |c, i| bits[c].update(i, x));
32 }
33 Query::Sum { v, l, r } => {
34 let mut ans = if l == 0 && 0 < r { a[v] } else { 0 };
35 cq.for_each_contour_range(v, l, r, |c, start, end| {
36 ans += bits[c].fold_abelian(start, end);
37 });
38 pp!(ans);
39 }
40 }
41 }
42}Trait Implementations§
Source§impl Clone for ContourQueryRange
impl Clone for ContourQueryRange
Auto Trait Implementations§
impl Freeze for ContourQueryRange
impl RefUnwindSafe for ContourQueryRange
impl Send for ContourQueryRange
impl Sync for ContourQueryRange
impl Unpin for ContourQueryRange
impl UnsafeUnpin for ContourQueryRange
impl UnwindSafe for ContourQueryRange
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