|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Disjoint Sparse Table for static range queries in O(1). More...
#include <bit>#include <cassert>#include <cstdlib>#include <concepts>#include <initializer_list>#include <type_traits>#include <vector>#include <utility>#include <algorithm>#include <tpl_array.H>#include <tpl_dynList.H>#include <ahFunction.H>#include <ah-errors.H>Go to the source code of this file.
Classes | |
| class | Aleph::Gen_Disjoint_Sparse_Table< T, Op > |
| Disjoint Sparse Table over an arbitrary associative binary operation. More... | |
| struct | Aleph::Sum_Disjoint_Sparse_Table< T > |
| Disjoint Sparse Table for range sum queries. More... | |
| struct | Aleph::Product_Disjoint_Sparse_Table< T > |
| Disjoint Sparse Table for range product queries. More... | |
Namespaces | |
| namespace | Aleph |
| Main namespace for Aleph-w library functions. | |
Concepts | |
| concept | Aleph::DisjointSparseTableOp |
| Binary operation compatible with Disjoint Sparse Table queries. | |
Disjoint Sparse Table for static range queries in O(1).
A Disjoint Sparse Table preprocesses a fixed array of n elements over an associative binary operation (not necessarily idempotent) and answers arbitrary range queries in O(1) time after an O(n log n) build phase.
Unlike the classical Sparse Table (which requires idempotency), the disjoint variant works for any associative operation: addition, multiplication, XOR, matrix multiplication, string concatenation, modular arithmetic, etc.
The technique decomposes the array into disjoint blocks at each level and stores prefix/suffix aggregates from each block's midpoint. Because the sub-ranges never overlap, no idempotency is needed.
Three class templates are provided:
Op.Aleph::plus<T>.Aleph::multiplies<T>.| Operation | Time |
|---|---|
| Construction | O(n log n) |
| query | O(1) |
| get | O(1) |
| Space | O(n log n) |
| Feature | Sparse Table | Disjoint Sparse Table |
|---|---|---|
| Operation requirement | Assoc. + idempotent | Associative only |
| Works for sum/product | No | Yes |
| Works for min/max | Yes | Yes |
| Query time | O(1) | O(1) |
| Build time | O(n log n) | O(n log n) |
Definition in file tpl_disjoint_sparse_table.H.