Problem Link: https://www.spoj.com/problems/RACETIME/
My solution Link: https://ideone.com/lfWNVt
it will be very helpful if someone analysis the time complexity of my solution
or give me some idea to solve these kinds of problem problems with the segment tree.