Queries to find the XOR of an Array after replacing all occurrences of X by Y | Stores the bitwise XOR of array elements ; Function to find the total xor ; Loop to find the xor of all the elements ; Function to find the XOR after replacing all occurrences of X by Y for Q queries ; Remove contribution of X from total_xor ; Adding contribution of Y to total_xor ; Print total_xor ; Driver Code
global total_xor NEW_LINE total_xor = 0 NEW_LINE def initialize_xor ( arr , n ) : NEW_LINE INDENT global total_xor NEW_LINE for i in range ( n ) : NEW_LINE INDENT total_xor = total_xor ^ arr [ i ] NEW_LINE DEDENT DEDENT def find_xor ( X , Y ) : NEW_LINE INDENT global total_xor NEW_LINE total_xor = total_xor ^ X NEW_LINE total_xor = total_xor ^ Y NEW_LINE print ( total_xor ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 5 , 7 , 8 , 9 ] NEW_LINE n = len ( arr ) NEW_LINE initialize_xor ( arr , n ) NEW_LINE Q = [ [ 5 , 6 ] , [ 8 , 1 ] ] NEW_LINE for i in range ( len ( Q ) ) : NEW_LINE INDENT find_xor ( Q [ i ] [ 0 ] , Q [ i ] [ 1 ] ) NEW_LINE DEDENT DEDENT