Stores the indices of element
unordered_map < int , int > index ; for ( int i = 0 ; i < n ; i ++ ) index [ arr [ i ] ] = i ; vector < int > boundary = { -1 , n } ; sort ( arr . begin ( ) , arr . end ( ) ) ;