Queries to update array by adding or multiplying array elements and print the element present at specified index | Function to modify the array by performing given queries ; Stores the multiplication of all integers of type 1 ; Stores the value obtained after performing queries of type 1 & 2 ; Iterate over the queries ; Query of type 0 ; Update the value of add ; Query of type 1 ; Update the value of mul ; Update the value of add ; Otherwise ; Store the element at index Q [ i ] [ 1 ] ; Prthe result for the current query ; Driver Code
def Query ( arr , N , Q ) : NEW_LINE INDENT mul = 1 NEW_LINE add = 0 NEW_LINE for i in range ( len ( Q ) ) : NEW_LINE INDENT if ( Q [ i ] [ 0 ] == 0 ) : NEW_LINE INDENT add = add + Q [ i ] [ 1 ] NEW_LINE DEDENT elif ( Q [ i ] [ 0 ] == 1 ) : NEW_LINE INDENT mul = mul * Q [ i ] [ 1 ] NEW_LINE add = add * Q [ i ] [ 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT ans = arr [ Q [ i ] [ 1 ] ] * mul + add NEW_LINE print ( ans , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 3 , 1 , 23 , 45 , 100 ] NEW_LINE N = len ( arr ) NEW_LINE Q = [ [ 1 , 2 ] , [ 0 , 10 ] , [ 2 , 3 ] , [ 1 , 5 ] , [ 2 , 4 ] ] NEW_LINE Query ( arr , N , Q ) NEW_LINE DEDENT