Queries to replace every array element by its XOR with a given value with updates | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define int  long long NEW_LINE void add ( vector < int > & arr , int x ) { arr . push_back ( x ) ; } void update ( int & effect , int x ) { effect = effect ^ x ; } void computeResults ( vector < int > & arr , int effect ) { for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { arr [ i ] = arr [ i ] ^ effect ; cout << arr [ i ] << " ▁ " ; } } signed main ( ) { vector < int > arr = { 0 } ; int effect = 0 ; add ( arr , 5 ) ; update ( effect , 2 ) ; computeResults ( arr , effect ) ; }