\(\langle O(N\log N), O(1) \rangle\) sparse table for certain binary operations like min
and gcd
.
More...
#include <sparse_table.hpp>
Public Types | |
using | size_type = std::size_t |
Public Member Functions | |
SparseTable ()=default | |
Creates an empty sparse table. | |
SparseTable (const std::vector< T > &data) | |
Construct the sparse table from the given sequence. | |
SparseTable (std::vector< T > &&data) | |
Construct the sparse table from the given sequence. | |
template<typename InputIt > | |
SparseTable (InputIt first, InputIt last) | |
Construct the sparse table from the given sequence. | |
size_type | size () const |
Returns number of elements in the sequence. | |
T | range (size_type left, size_type right) const |
Iterated application of operator Op on elements in the 0-based half-open range [left, right) . | |
\(\langle O(N\log N), O(1) \rangle\) sparse table for certain binary operations like min
and gcd
.
T | T Type of elements. |
Op | A function object that takes two T 's and returns a T . Must be associative, commutative and idempotent. |
|
inline |
Construct the sparse table from the given sequence.
Makes \(O(N\log N)\) calls to Op
and creates \(O(N\log N)\) copies of sequence elements.
|
inline |
Construct the sparse table from the given sequence.
Makes \(O(N\log N)\) calls to Op
and creates \(O(N\log N)\) copies of sequence elements.
|
inline |
Construct the sparse table from the given sequence.
Makes \(O(N\log N)\) calls to Op
and creates \(O(N\log N)\) copies of sequence elements.
|
inline |
Iterated application of operator Op
on elements in the 0-based half-open range [left, right)
.
If \(\circ\) denotes Op
, this returns \(a_{left} \cdots a_{left+1} \circ \dots \circ a_{right-1}\). Time complexity is \(O(1)\) and specfically Op
is called at most once.
Requires 0 <= left < right <= size()
. Note that empty range is not allowed.