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
let total_xor ; function initialize_xor ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) { total_xor = total_xor ^ arr [ i ] ; } } function find_xor ( X , Y ) { total_xor = total_xor ^ X ; total_xor = total_xor ^ Y ; document . write ( total_xor + " " ) ; } let arr = [ 5 , 7 , 8 , 9 ] ; let n = arr . length ; initialize_xor ( arr , n ) ; let Q = [ [ 5 , 6 ] , [ 8 , 1 ] ] ; for ( let i = 0 ; i < Q . length ; i ++ ) { find_xor ( Q [ i ] [ 0 ] , Q [ i ] [ 1 ] ) ; }