Efficient \(\langle O(N), O(1) \rangle\) static range minimum query. More...
#include <rmq.hpp>
Public Types | |
using | size_type = std::size_t |
Public Member Functions | |
RangeMinQuery ()=default | |
Creates an empty RangeMinQuery. | |
RangeMinQuery (const std::vector< T > &arr) | |
Construct the range minumum query object from the given sequence. | |
RangeMinQuery (std::vector< T > &&arr) | |
Construct the range minumum query object from the given sequence. | |
template<typename InputIt > | |
RangeMinQuery (InputIt first, InputIt last) | |
Construct the range minumum query object from the given sequence. | |
size_type | size () const |
Returns number of elements in the sequence. | |
T | range_min (size_type left, size_type right) const |
Returns the minimum element in the 0-based half-open range [left, right) . | |
Static Public Attributes | |
static constexpr int | block_size = impl::RangeMinBlock::bitmap_size |
Efficient \(\langle O(N), O(1) \rangle\) static range minimum query.
Divides input sequence into machine word sized blocks. Uses bit operations for in-block queries, and SparseTable for inter-block queries. Under the transdichotomous model ( \(w\geq\log_2 N\) where \(w=64\) is the word size), initialization takes \(O(N)\) time.
T | Type of elements. |
Comp | Comparison function type that is passed to std::min . Must satisfy C++ named requirement Compare. |
|
inline |
Construct the range minumum query object from the given sequence.
Makes \(O(N)\) calls to Comp
and creates \(O(N)\) copies of sequence elements along with \(O(N)\) integers as bit masks.
|
inline |
Construct the range minumum query object from the given sequence.
Makes \(O(N)\) calls to Comp
and creates \(O(N)\) copies of sequence elements along with \(O(N)\) integers as bit masks.
|
inline |
Construct the range minumum query object from the given sequence.
Makes \(O(N)\) calls to Comp
and creates \(O(N)\) copies of sequence elements along with \(O(N)\) integers as bit masks.
|
inline |
Returns the minimum element in the 0-based half-open range [left, right)
.
Returns \(\min\{a_{left},a_{left+1},\dots,a_{right-1}\}\). Time complexity is \(O(1)\) and specifically Comp
is called at most 3 times.
Requires 0 <= left < right <= size()
. Note that empty range is not allowed.