I’m trying to solve this problem and getting RE in this cpp submission while having trouble implementing efficient fully dynamic variant as mentioned here.
Can anyone help me preferably in implementing Fully Dynamic variant of Convex Hull trick or correcting me in cpp solution with my mistake?
Lichao Segment Tree
This may interest you. It is easier to implement than a dynamic cht and has no disadvantages that I know of. I learnt it recently so I could be wrong about that.
First of all the implementation you are following has many bugs in the add_line() function. Here is a fixed version: pastebin link.
And secondly, your swapping method below
if(tmp.size() > h.size()){
hull_optimizer t = tmp;
tmp = h;
h = t;
}
is not good because writing x = y for 2 objects in C++ makes x an exact copy of y. So here you will be copying the hull with all its lines back and forth. The complexity no longer remains \mathcal{O}(n \log n).
To maintain the small-to-large trick and \mathcal{O}(n \log n) complexity you want to swap pointers instead of copying whole objects. If you don’t want to deal with pointers you could also swap array indices like so: 36878762.