Find the XOR of the elements in the given range [ L , R ] with the value K for a given set of queries | Function to perform the update operation on the given array ; Converting the indices to 0 indexing . ; Saving the XOR of K from the starting index in the range [ L , R ] . ; Saving the XOR of K at the ending index in the given [ L , R ] . ; Function to display the resulting array ; Finding the resultant value in the result array ; Combining the effects of the updates with the original array without changing the initial array . ; Driver code ; Query 1 ; Query 2 ; Query 3
def update ( res , L , R , K ) : NEW_LINE INDENT L = L - 1 NEW_LINE R = R - 1 NEW_LINE res [ L ] = res [ L ] ^ K NEW_LINE res [ R + 1 ] = res [ R + 1 ] ^ K NEW_LINE DEDENT def display ( arr , res , n ) : NEW_LINE INDENT for i in range ( 1 , n ) : NEW_LINE INDENT res [ i ] = res [ i ] ^ res [ i - 1 ] NEW_LINE DEDENT for i in range ( 0 , n ) : NEW_LINE INDENT print ( arr [ i ] ^ res [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT arr = [ 2 , 4 , 6 , 8 , 10 ] NEW_LINE N = len ( arr ) NEW_LINE res = [ 0 ] * N NEW_LINE L = 1 NEW_LINE R = 3 NEW_LINE K = 2 NEW_LINE update ( res , L , R , K ) NEW_LINE L = 2 NEW_LINE R = 4 NEW_LINE K = 3 NEW_LINE update ( res , L , R , K ) NEW_LINE display ( arr , res , N ) NEW_LINE