Count subarrays having even Bitwise XOR | Function to count subarrays having even Bitwise XOR ; Store the required result ; Stores count of subarrays with even and odd XOR values ; Stores Bitwise XOR of current subarray ; Traverse the array ; Update current Xor ; If XOR is even ; Update ans ; Increment count of subarrays with even XOR ; Otherwise , increment count of subarrays with odd XOR ; Print the result ; Given array ; Stores the size of the array
def evenXorSubarray ( arr , n ) : NEW_LINE INDENT ans = 0 NEW_LINE freq = [ 0 ] * n NEW_LINE XOR = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT XOR = XOR ^ arr [ i ] NEW_LINE if ( XOR % 2 == 0 ) : NEW_LINE INDENT ans += freq [ 0 ] + 1 NEW_LINE freq [ 0 ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans += freq [ 1 ] NEW_LINE freq [ 1 ] += 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 4 ] NEW_LINE N = len ( arr ) NEW_LINE evenXorSubarray ( arr , N ) NEW_LINE