A depot report combines four requests that happen to mention ranges but demand different indexes. Daily capacities can be corrected in place and summed. An immutable sensor batch needs position-bounded threshold counts. A frozen scan array needs many associative aggregate queries. A growing offer book needs the least linear charge at selected integer quantities. Build a tiny plain reference for each: list slicing for sums, a filtered slice for threshold counts, the built-in sum for frozen intervals, and a scan of every tariff line for each quantity. Compare outputs after every operation. The references should remain separate because a structure that answers one contract does not automatically support the others.
Project: audit four range-query workloads
Acceptance trace
Use capacities 23, 47, 19, 61, 38, 52, 29; replace position three with 74 and require 230 over [1, 6). Use readings 41, 18, 41, 73, 26, 55, 12 and require three values at most 41 over [1, 6). On the original capacity snapshot, require 217 over [1, 6), 61 over [3, 4), and zero over [2, 2). Insert tariffs 7x+13, 4x+49, and 9x-11 over integer x from zero through 80; require minimums 34 at five and 189 at 35. These checks expose both endpoint convention and the distinction between a mutable index and a frozen snapshot.
Expected output
corrected-sum=230 threshold-count=3 frozen-sum=217
tariff-at-5=34 tariff-at-35=189Boundary and cost review
Try an empty array, empty intervals, duplicate threshold values, a negative capacity correction, an empty tariff book, and a query just outside the declared quantity domain. Then state which edits require rebuilding each immutable index. Compare query-heavy and update-heavy workloads before choosing a structure. Measure memory as well as steps: the two static tables replicate values across logarithmic levels, while the block index keeps the underlying array plus block totals. Document whether the workload truly needs the general associative table when a prefix sum would be cheaper.
Common Mistakes
- Do not include the stop position in a half-open query.
- Do not count a threshold equal to the bound as excluded.
- Do not use overlapping sparse-table intervals for addition.
- Do not query an empty tariff book or outside its domain.
