Function to return count of deleted indices which are to the left of the current index
function deleted ( seg , l , r , start , end , current ) { if ( end < l start > r ) return 0 ; if ( start >= l && end <= r ) return seg [ current ] ; let mid = parseInt ( ( start + end ) / 2 , 10 ) ; return deleted ( seg , l , r , start , mid , 2 * current + 1 ) + deleted ( seg , l , r , mid + 1 , end , 2 * current + 2 ) ; }