89 cout <<
"============================================================\n"
90 <<
" SCENARIO 1: Sensor Monitoring (Sparse_Table — range min)\n"
91 <<
"============================================================\n\n";
95 72.3, 71.8, 73.1, 69.5, 70.2, 68.9, 74.0, 71.1,
96 67.5, 70.8, 72.0, 73.5, 66.2, 69.0, 71.4, 75.1,
97 68.3, 70.0, 72.7, 69.8
100 cout <<
"Sensor readings (°C):\n\n";
101 cout <<
" Sensor Temperature\n"
102 <<
" ------ -----------\n";
104 for (
size_t i = 0; i <
temps.
size(); ++i)
110 <<
temps.num_levels() <<
" levels\n";
113 struct Query {
size_t l;
size_t r;
const char *label; };
115 { 0, 4,
"Sensors 0-4 (left bank)" },
116 { 3, 10,
"Sensors 3-10 (center section)" },
117 { 10, 19,
"Sensors 10-19 (right bank)" },
118 { 0, 19,
"All sensors (full bank)" },
119 { 12, 12,
"Sensor 12 alone" },
120 { 5, 8,
"Sensors 5-8 (hot zone)" },
123 cout <<
"\nRange minimum queries:\n\n";
124 cout <<
" Range Min °C Description\n"
125 <<
" ---------- ------- ----------------------------\n";
129 double mn =
temps.query(q.l, q.r);
130 cout <<
" [" <<
setw(2) << q.l <<
", " <<
setw(2) << q.r <<
"]"
132 <<
" " << q.label <<
"\n";
137 for (
size_t i = 4; i <= 10; ++i)
141 cout <<
"\n ✓ Brute-force verification passed for [3, 10]\n";
153 cout <<
"\n\n============================================================\n"
154 <<
" SCENARIO 2: Sports Leaderboard (Max_Sparse_Table — range max)\n"
155 <<
"============================================================\n\n";
158 9.1, 8.7, 9.4, 8.9, 9.6, 9.0, 8.5, 9.8,
159 9.2, 8.8, 9.5, 9.3, 8.6, 9.7, 9.1
163 "Simone B.",
"Kohei U.",
"Nadia C.",
"Daiki H.",
164 "Gabby D.",
"Yul M.",
"Marian D.",
"Larisa L.",
165 "Nastia L.",
"Vitaly S.",
"Olga K.",
"Li Ning",
166 "Mary Lou",
"Sawao K.",
"Nellie K."
169 cout <<
"Routine scores:\n\n";
170 cout <<
" # Athlete Score\n"
171 <<
" -- ----------- -----\n";
179 struct Query {
size_t l;
size_t r;
const char *label; };
181 { 0, 4,
"First group (0-4)" },
182 { 5, 9,
"Second group (5-9)" },
183 { 10, 14,
"Third group (10-14)" },
184 { 0, 14,
"Overall best" },
185 { 3, 7,
"Mid-competition (3-7)" },
186 { 7, 7,
"Single routine (#7)" },
189 cout <<
"\nRange maximum queries:\n\n";
190 cout <<
" Range Max Description\n"
191 <<
" ---------- ------ ----------------------\n";
196 cout <<
" [" <<
setw(2) << q.l <<
", " <<
setw(2) << q.r <<
"]"
198 <<
" " << q.label <<
"\n";
203 cout <<
"\n ✓ Overall best = 9.8 (Larisa L.) — verified\n";
215 cout <<
"\n\n============================================================\n"
216 <<
" SCENARIO 3: Range GCD (Gen_Sparse_Table — custom op)\n"
217 <<
"============================================================\n\n";
221 int operator()(
const int & a,
const int & b)
const noexcept
227 Gen_Sparse_Table<int, Gcd_Op> st = {12, 18, 24, 36, 60, 48, 30, 90, 15, 45};
230 for (
size_t i = 0; i < st.
size(); ++i)
231 cout << (i ?
", " :
"") << st.
get(i);
234 cout <<
"Table info: " << st.
size() <<
" elements, "
237 struct Query {
size_t l;
size_t r; };
239 {0, 2}, {0, 9}, {3, 5}, {1, 4}, {6, 9}, {4, 4}, {0, 5}, {7, 9},
242 cout <<
"Range GCD queries:\n\n";
243 cout <<
" Range GCD Values\n"
244 <<
" -------- ---- ------\n";
248 int g = st.
query(q.l, q.r);
251 cout <<
" [" << q.l <<
", " << q.r <<
"]"
252 <<
setw(6 - (q.r > 9 ? 1 : 0) - (q.l > 9 ? 1 : 0)) <<
""
253 <<
setw(4) << g <<
" {";
254 for (
size_t i = q.l; i <= q.r; ++i)
255 cout << (i > q.l ?
", " :
"") << st.
get(i);
260 for (
size_t i = q.l + 1; i <= q.r; ++i)
265 cout <<
"\n ✓ All GCD queries verified against brute-force\n";
273 cout <<
"\n\n============================================================\n"
274 <<
" SCENARIO 4: Construction from different containers\n"
275 <<
"============================================================\n\n";
280 cout <<
"From Array<int>: min[0,8] = " <<
st_arr.query(0, 8) <<
"\n";
283 vector<int>
vec = {5, 3, 7, 1, 9, 2, 8, 4, 6};
285 cout <<
"From vector<int>: min[0,8] = " <<
st_vec.query(0, 8) <<
"\n";
290 cout <<
"From DynList<int>: min[0,8] = " <<
st_dl.query(0, 8) <<
"\n";
294 cout <<
"From init-list: min[0,8] = " <<
st_il.query(0, 8) <<
"\n";
303 cout <<
"\nReconstructed values: ";
304 for (
size_t i = 0; i <
vals.
size(); ++i)
308 cout <<
"\n ✓ All construction methods produce identical results\n";
Simple dynamic array with automatic resizing and functional operations.
Dynamic singly linked list with functional programming support.
Sparse Table over an arbitrary associative and idempotent binary operation.
T get(const size_t i) const
Retrieve the value a[i] in O(1).
constexpr size_t num_levels() const noexcept
Number of precomputed levels (floor(log2(n)) + 1).
constexpr size_t size() const noexcept
Number of logical elements.
T query(const size_t l, const size_t r) const
Range query over [l, r] in O(1).
size_t size() const noexcept
Count the number of elements of the list.
T brute_min(const vector< T > &v, size_t l, size_t r)
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_min_function > > min(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
static void scenario_sports_leaderboard()
static void scenario_construction()
static void scenario_range_gcd()
static void scenario_sensor_monitoring()
Sparse Table for range maximum queries.
Sparse Table for range minimum queries.
int operator()(const int &a, const int &b) const noexcept
Sparse Table for static range queries in O(1).