Special Segments of Permutation

CodeForces - 1156E