|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Sparse Table applied to competitive programming and sensor analysis. More...
#include <cstdio>#include <iostream>#include <iomanip>#include <numeric>#include <cassert>#include <tpl_sparse_table.H>Go to the source code of this file.
Functions | |
| static void | scenario_sensor_monitoring () |
| static void | scenario_sports_leaderboard () |
| static void | scenario_range_gcd () |
| static void | scenario_construction () |
| int | main () |
Sparse Table applied to competitive programming and sensor analysis.
This example demonstrates the three Sparse Table variants through realistic scenarios.
An industrial plant has a row of temperature sensors sampled once per second. After the sampling window closes, operations needs to answer many queries of the form "what was the coldest reading between second l and second r?" The data is static (the window is already closed), so a Sparse Table gives O(1) per query after an O(n log n) build.
A swimming competition records lap times for each swimmer. The commentator wants to quickly find the best (fastest) lap in any contiguous block of laps. Since lower time = better, we actually want range minimum on times; but to showcase Max_Sparse_Table we track scores (higher = better) assigned by judges.
A number-theory teaching tool: given a sequence of integers, answer range-GCD queries in O(1). GCD is idempotent (gcd(a, a) = a), so it fits the Sparse Table perfectly.
g++ -std=c++20 -I.. -o sparse_table_example sparse_table_example.cc ./sparse_table_example
Definition in file sparse_table_example.cc.
| int main | ( | ) |
Definition at line 313 of file sparse_table_example.cc.
References Aleph::maps(), scenario_construction(), scenario_range_gcd(), scenario_sensor_monitoring(), and scenario_sports_leaderboard().
|
static |
Definition at line 271 of file sparse_table_example.cc.
References Aleph::maps(), and Aleph::HTList::size().
Referenced by main().
|
static |
Definition at line 213 of file sparse_table_example.cc.
References Aleph::Gen_Sparse_Table< T, Op >::get(), l, Aleph::maps(), Aleph::Gen_Sparse_Table< T, Op >::num_levels(), Gcd_Op::operator()(), Aleph::Gen_Sparse_Table< T, Op >::query(), and Aleph::Gen_Sparse_Table< T, Op >::size().
Referenced by main().
|
static |
Definition at line 87 of file sparse_table_example.cc.
References brute_min(), Aleph::DynList< T >::get(), l, Aleph::maps(), min(), and Aleph::HTList::size().
Referenced by main().
|
static |
Definition at line 151 of file sparse_table_example.cc.
References Aleph::DynList< T >::get(), l, Aleph::maps(), and Aleph::HTList::size().
Referenced by main().