Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
range_queries::heavy_light_decomposition::SG< X > Class Template Reference

Segment Tree, to store heavy chains. More...

Inheritance diagram for range_queries::heavy_light_decomposition::SG< X >:
[legend]
Collaboration diagram for range_queries::heavy_light_decomposition::SG< X >:
[legend]

Private Member Functions

combine (X lhs, X rhs)
 Function that specifies the type of operation involved when segments are combined.
 
 SG (int size)
 Class parameterized constructor. Resizes the and initilizes the data members.
 
void update (int p, X v)
 Update the value at a node.
 
query (int l, int r)
 Make a range query from node label l to node label r.
 
void set_sret_init (X new_sret_init)
 Set the initialization for the query data type, based on requirement.
 

Private Attributes

std::vector< X > s_tree
 Everything here is private, and can only be accessed through the methods, in the derived class (HLD)
 
int s_size
 number of leaves in the segment tree
 
sret_init = 0
 inital query return value
 

Friends

template<typename T >
class HLD
 

Detailed Description

template<typename X>
class range_queries::heavy_light_decomposition::SG< X >

Segment Tree, to store heavy chains.

Template Parameters
thedata type of the values stored in the tree nodes

Constructor & Destructor Documentation

◆ SG()

template<typename X >
range_queries::heavy_light_decomposition::SG< X >::SG ( int size)
inlineexplicitprivate

Class parameterized constructor. Resizes the and initilizes the data members.

Parameters
nodesthe total number of nodes in the tree
Returns
void
282 {
283 s_size = size;
284 s_tree.assign(2 * s_size, 0ll);
285 }
T assign(T... args)
int s_size
number of leaves in the segment tree
Definition heavy_light_decomposition.cpp:263
std::vector< X > s_tree
Everything here is private, and can only be accessed through the methods, in the derived class (HLD)
Definition heavy_light_decomposition.cpp:262
Here is the call graph for this function:

Member Function Documentation

◆ combine()

template<typename X >
X range_queries::heavy_light_decomposition::SG< X >::combine ( X lhs,
X rhs )
inlineprivate

Function that specifies the type of operation involved when segments are combined.

Parameters
lhsthe left segment
rhsthe right segment
Returns
the combined result
274{ return lhs + rhs; }

◆ query()

template<typename X >
X range_queries::heavy_light_decomposition::SG< X >::query ( int l,
int r )
inlineprivate

Make a range query from node label l to node label r.

Parameters
lnode label where the path starts
rnode label where the path ends
Returns
void
305 {
306 X lhs = sret_init, rhs = sret_init;
307 for (l += s_size, r += s_size + 1; l < r; l >>= 1, r >>= 1) {
308 if (l & 1) {
309 lhs = combine(lhs, s_tree[l++]);
310 }
311 if (r & 1) {
312 rhs = combine(s_tree[--r], rhs);
313 }
314 }
315 return combine(lhs, rhs);
316 }
X combine(X lhs, X rhs)
Function that specifies the type of operation involved when segments are combined.
Definition heavy_light_decomposition.cpp:274
X sret_init
inital query return value
Definition heavy_light_decomposition.cpp:264
Here is the call graph for this function:

◆ set_sret_init()

template<typename X >
void range_queries::heavy_light_decomposition::SG< X >::set_sret_init ( X new_sret_init)
inlineprivate

Set the initialization for the query data type, based on requirement.

Change the sret_init, based on requirement:

  • Sum Query: 0 (Default)
  • XOR Query: 0 (Default)
  • Min Query: Infinity
  • Max Query: -Infinity
    Parameters
    new_sret_initthe new init
329{ sret_init = new_sret_init; }

◆ update()

template<typename X >
void range_queries::heavy_light_decomposition::SG< X >::update ( int p,
X v )
inlineprivate

Update the value at a node.

Parameters
pthe node to be udpated
vthe update value
Returns
void
293 {
294 for (p += s_size; p > 0; p >>= 1) {
295 s_tree[p] += v;
296 }
297 }

Member Data Documentation

◆ s_tree

template<typename X >
std::vector<X> range_queries::heavy_light_decomposition::SG< X >::s_tree
private

Everything here is private, and can only be accessed through the methods, in the derived class (HLD)

the segment tree, stored as a vector


The documentation for this class was generated from the following file: