Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
segment_tree_example.cc File Reference

Four creative scenarios demonstrating Segment Tree variants. More...

#include <tpl_segment_tree.H>
#include <tpl_sparse_table.H>
#include <iostream>
#include <iomanip>
Include dependency graph for segment_tree_example.cc:

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 ()
 

Detailed Description

Four creative scenarios demonstrating Segment Tree variants.

SCENARIO 1 — "El Arbol del Tiempo" (Min_Segment_Tree)

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.

SCENARIO 2 — "Ajustes salariales" (Lazy_Sum_Segment_Tree)

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.

SCENARIO 3 — "Balanceo de servidores" (Segment_Tree_Beats)

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.

SCENARIO 4 — "RMQ dinámico vs estático"

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.

Function Documentation

◆ main()

◆ scenario_1_el_arbol_del_tiempo()

static void scenario_1_el_arbol_del_tiempo ( )
static

◆ scenario_2_ajustes_salariales()

static void scenario_2_ajustes_salariales ( )
static

◆ scenario_3_balanceo_servidores()

static void scenario_3_balanceo_servidores ( )
static

◆ scenario_4_rmq_comparison()

static void scenario_4_rmq_comparison ( )
static

Definition at line 183 of file segment_tree_example.cc.

References Aleph::divide_and_conquer_partition_dp(), l, and r.

Referenced by main().