Queries to replace every array element by its XOR with a given value with updates | Java program of the above approach ; Function to insert an element into the array ; Function to update every array element a [ i ] by a [ i ] ^ x ; Function to compute the final results after the operations ; Driver Code ; Queries ; Function Call
import java . util . * ; class GFG { static Vector < Integer > arr = new Vector < Integer > ( ) ; static int effect ; static void add ( int x ) { arr . add ( x ) ; } static void update ( int x ) { effect = effect ^ x ; } static void computeResults ( ) { for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { arr . set ( i , arr . get ( i ) ^ effect ) ; System . out . print ( arr . get ( i ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { arr = new Vector < Integer > ( ) ; arr . add ( 0 ) ; effect = 0 ; add ( 5 ) ; update ( 2 ) ; computeResults ( ) ; } }