|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Four creative scenarios demonstrating Segment Tree variants. More...
Go to the source code of this file.
Functions | |
| static void | scenario_1_el_arbol_del_tiempo () |
| static void | scenario_2_ajustes_salariales () |
| static void | scenario_3_balanceo_servidores () |
| static void | scenario_4_rmq_comparison () |
| int | main () |
Four creative scenarios demonstrating Segment Tree variants.
A historian maintains a timeline of the oldest known artifact per century (indices 0..9 represent centuries 1-10). She queries "what is the oldest artifact across centuries 3-7?" and updates individual centuries when new archaeological discoveries push dates further back.
An HR system tracks salaries by department index. Corporate announces range raises ("add $500 to departments 3-7") and the CFO queries "total payroll for departments 2-5". This is the canonical range-update + range-query pattern.
A data center has server racks with varying load. Operations applies chmin (cap load) and chmax (set minimum floor) across rack ranges, then queries total load per section.
Side-by-side comparison showing when to use Sparse Table (static, O(1) query) vs Segment Tree (dynamic, O(log n) query).
Definition in file segment_tree_example.cc.
| int main | ( | void | ) |
Definition at line 224 of file segment_tree_example.cc.
References scenario_1_el_arbol_del_tiempo(), scenario_2_ajustes_salariales(), scenario_3_balanceo_servidores(), and scenario_4_rmq_comparison().
|
static |
Definition at line 69 of file segment_tree_example.cc.
References Aleph::Gen_Segment_Tree< T, Op >::get(), Aleph::Gen_Segment_Tree< T, Op >::query(), Aleph::Gen_Segment_Tree< T, Op >::set(), and Aleph::Gen_Segment_Tree< T, Op >::size().
Referenced by main().
|
static |
Definition at line 109 of file segment_tree_example.cc.
References Aleph::Gen_Lazy_Segment_Tree< Policy >::get(), Aleph::Gen_Lazy_Segment_Tree< Policy >::query(), Aleph::Gen_Lazy_Segment_Tree< Policy >::size(), and Aleph::Gen_Lazy_Segment_Tree< Policy >::update().
Referenced by main().
|
static |
Definition at line 146 of file segment_tree_example.cc.
References Aleph::Segment_Tree_Beats< T >::chmax(), Aleph::Segment_Tree_Beats< T >::chmin(), Aleph::Segment_Tree_Beats< T >::get(), Aleph::Segment_Tree_Beats< T >::query_max(), Aleph::Segment_Tree_Beats< T >::query_min(), Aleph::Segment_Tree_Beats< T >::query_sum(), and Aleph::Segment_Tree_Beats< T >::size().
Referenced by main().
|
static |
Definition at line 183 of file segment_tree_example.cc.
References l, Aleph::Gen_Segment_Tree< T, Op >::query(), Aleph::Gen_Sparse_Table< T, Op >::query(), r, and Aleph::Gen_Segment_Tree< T, Op >::set().
Referenced by main().