Queries to find the XOR of an Array after replacing all occurrences of X by Y | C # program to implement the above approach ; 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
using System ; class GFG { static int total_xor ; static void initialize_xor ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) { total_xor = total_xor ^ arr [ i ] ; } } static void find_xor ( int X , int Y ) { total_xor = total_xor ^ X ; total_xor = total_xor ^ Y ; Console . Write ( total_xor + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 7 , 8 , 9 } ; int n = arr . Length ; initialize_xor ( arr , n ) ; int [ , ] Q = { { 5 , 6 } , { 8 , 1 } } ; for ( int i = 0 ; i < Q . GetLength ( 0 ) ; i ++ ) { find_xor ( Q [ i , 0 ] , Q [ i , 1 ] ) ; } } }