Range Sorting (Hard Version)

CodeForces - 1827B2