Hi. I recently overcomplicated one easy-ish geometry problem and encountered the following difficulty.
Let's say I have a set of linear functions f(x) = ax + b and two types of online queries:
- Given a and b, insert a new linear function.
- Given x0, print the maximum value f(x0).
I can handle both queries in logarithmic time by using BST and maintaining the convex hull of linear functions. Can I do the same (easily?) using set in C++? The problem is that the second query requires lower_bound that is able to say whether a linear function is on the left or on the right from the optimal one. I think it's impossible because it depends on the neighboring (after sorting CH by slope) functions.
During a contest, I implemented something in O(log2) — a lower_bound that runs an internal lower_bound to find the next linear function in the set. Later I came up with an idea to extend a linear-function struct to also store a copy of the next function in the set. It requires some extra work but should work and should be O(log), right? Do you see any easier way?







. What should be stored in such a tree?

code in C++, with binary search:
from the starting cell. That sum can't exceed
what is enough to get AC. It isn't hard to get rid of the logarithm factor what you can see in the last code below.





. The limit from the statement is 


or better.

where

.
.
where
let's keep the distance to the next power of 42. After each "add on the interval" we should find the minimum and check if it's positive. If not then we should change value of the closest power of 
. Changing one coefficient affects up to
consecutive bits there and we want to get a sequence with only
(and at the end we want at least
). At the same time, we should keep people in
and it doesn't depend on a constant
or faster. Can you solve the problem in linear time?
. Then, check if the max flow in this graph is at least
where
is from using set of forbidden edges.
but you could get AC with very fast solution with extra 


