So here is the cses problem https://cses.fi/problemset/task/1163
So after every new position, I can break the segment into two smaller segments and then calculate their lengths and repeat for all the inputs. Also use binary search to find where the new position will be, that is in which segment would it be added to.
What I am getting stuck at is the implementation part. Can someone please help me?