Dynamic Programming21 sections · 916 units
Open in Course

Challenge: Online Queries

Query the function at points

Standard Slope Trick gives the minimum. What if we need f(x)f(x) for arbitrary xx? Count breakpoints to the left of xx. Each adds 11 to slope.

Compute f(x)f(x) from base + slope integral. Efficient query: use ordered set (like C++ set) instead of heaps. O(logn)O(\log n) per query. Trade-off: heaps are simpler and faster for operations, but don't support arbitrary queries. For arbitrary point queries, replace heaps with ordered sets. This gives O(logn)O(log n) query at the cost of complexity.