For the length of strictly larger numbers on the right of A [ i ]
for ( int i = N - 1 ; i >= 0 ; i -- ) { int count = 1 ; while ( ! r . empty ( ) && r . top ( ) . first >= arr [ i ] ) { count += r . top ( ) . second ; r . pop ( ) ; } r . push ( { arr [ i ] , count } ) ;