human
Count subsequences for every array element in which they are the maximum | Function to merge the subarrays arr [ l . . m ] and arr [ m + 1 , . . r ] based on indices [ ].
If a [ indices [ l ] ] is less than a [ indices [ j ] ] , add indice [ l ] to temp.
Else add indices [ j ].
Add remaining elements.
Add remainging elements.
Recursive function to divide the array into to parts.
Recursive call for elements before mid.
Recursive call for elements after mid.
Merge the two sorted arrays.
Function to find the number of subsequences for each element.
Sorting the indices according to array arr [ ].
Array to store output numbers.
Initialize subseq.
B [ i ] is 2 ^ i.
Doubling the subsequences.
Print the final output , array B [ ].
Driver Code.
Given array.
Given length.
Function call"
Solution in Python:
 What is a code to count subsequences for every array element in which they are the maximum and the other steps required?
assistant
#Here is code to count subsequences for every array element in which they are the maximum and the other steps required.
 def merge ( indices , a , l , mid , r ) :
	temp_ind = [ 0 ] * ( r - l + 1 )
	j = mid + 1
	i = 0
	temp_l = l
	while ( l <= mid and j <= r ) :
		if ( a [ indices [ l ] ] < a [ indices [ j ] ] ) :
			temp_ind [ i ] = indices [ l ]
			i += 1
			l += 1
		else :
			temp_ind [ i ] = indices [ j ]
			i += 1
			j += 1
	while ( l <= mid ) :
		temp_ind [ i ] = indices [ l ]
		i += 1
		l += 1
	while ( j <= r ) :
		temp_ind [ i ] = indices [ j ]
		i += 1
		j += 1
	for k in range ( i ) :
		indices [ temp_l ] = temp_ind [ k ]
		temp_l += 1
def divide ( indices , a , l , r ) :
	if ( l >= r ) :
		return
	mid = l // 2 + r // 2
	divide ( indices , a , l , mid )
	divide ( indices , a , mid + 1 , r )
	merge ( indices , a , l , mid , r )
def noOfSubsequences ( arr , N ) :
	indices = N * [ 0 ]
	for i in range ( N ) :
		indices [ i ] = i
	divide ( indices , arr , 0 , N - 1 )
	B = [ 0 ] * N
	subseq = 1
	for i in range ( N ) :
		B [ indices [ i ] ] = subseq
		subseq *= 2
	for i in range ( N ) :
		print ( B [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
	arr = [ 2 , 3 , 1 ]
	N = len ( arr )
	noOfSubsequences ( arr , N )