Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
data_structures::sparse_table::Sparse_table Struct Reference
Collaboration diagram for data_structures::sparse_table::Sparse_table:
[legend]

Public Member Functions

int64_t query (int64_t l, int64_t r)
 Queries the sparse table for the value of the interval [l, r] (i.e. from l to r inclusive).
 

Public Attributes

size_t n = 0
 size of input array.
 
std::array< int64_t, NA = {}
 input array to perform RMQ.
 
std::array< std::array< int64_t, N >, MST {}
 the sparse table storing min() values for given interval.
 
std::array< int64_t, NLOG = {}
 where floor(log2(i)) are precomputed.
 

Member Function Documentation

◆ query()

int64_t data_structures::sparse_table::Sparse_table::query ( int64_t l,
int64_t r )
inline

Queries the sparse table for the value of the interval [l, r] (i.e. from l to r inclusive).

Parameters
lthe left index of the range (inclusive).
rthe right index of the range (inclusive).
Returns
the computed value of the given interval. @complexity: O(1)

< smallest power of 2 covering [l,r]

< represents minimum value over the range [g,l]

< represents minimum value over the range [g, r - pow(2,g) + 1]

< represents minimum value over the whole range [l,r]

109 {
110 int64_t g = LOG[r - l + 1]; ///< smallest power of 2 covering [l,r]
111 int64_t x = ST[g][l]; ///< represents minimum value over the range
112 ///< [g,l]
113 int64_t y =
114 ST[g][r - (1 << g) + 1]; ///< represents minimum value over the
115 ///< range [g, r - pow(2,g) + 1]
116
117 return (A[x] <= A[y] ? x : y); ///< represents minimum value over
118 ///< the whole range [l,r]
119 }
double g(double x)
Another test function.
Definition composite_simpson_rule.cpp:115
double l(double x)
Another test function.
Definition composite_simpson_rule.cpp:119
std::array< int64_t, N > LOG
where floor(log2(i)) are precomputed.
Definition sparse_table.cpp:59
std::array< int64_t, N > A
input array to perform RMQ.
Definition sparse_table.cpp:56
std::array< std::array< int64_t, N >, M > ST
the sparse table storing min() values for given interval.
Definition sparse_table.cpp:58

Member Data Documentation

◆ A

std::array<int64_t, N> data_structures::sparse_table::Sparse_table::A = {}

input array to perform RMQ.

Warning
check if N is not less than n. if so, manually increase the value of N
56{}; ///< input array to perform RMQ.

◆ LOG

std::array<int64_t, N> data_structures::sparse_table::Sparse_table::LOG = {}

where floor(log2(i)) are precomputed.

59{}; ///< where floor(log2(i)) are precomputed.

◆ ST

std::array<std::array<int64_t, N>, M> data_structures::sparse_table::Sparse_table::ST {}

the sparse table storing min() values for given interval.

58{}; ///< the sparse table storing `min()` values for given interval.

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