Count even length subarrays having bitwise XOR equal to 0 | Python3 program to implement the above approach ; Function to get the count of even length subarrays having bitwise xor 0 ; Stores prefix - xor of the given array ; Stores prefix - xor at even index of the array . ; Stores prefix - xor at odd index of the array . ; Stores count of subarrays that satisfy the condition ; length from 0 index to odd index is even ; Traverse the array . ; Take prefix - xor ; If index is odd ; Calculate pairs ; Increment prefix - xor at odd index ; Calculate pairs ; Increment prefix - xor at odd index ; Driver Code
M = 1000000 ; NEW_LINE def cntSubXor ( arr , N ) : NEW_LINE INDENT prefixXor = 0 ; NEW_LINE Even = [ 0 ] * M ; NEW_LINE Odd = [ 0 ] * M ; NEW_LINE cntSub = 0 ; NEW_LINE Odd [ 0 ] = 1 ; NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT prefixXor ^= arr [ i ] ; NEW_LINE if ( i % 2 == 1 ) : NEW_LINE INDENT cntSub += Odd [ prefixXor ] ; NEW_LINE Odd [ prefixXor ] += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT cntSub += Even [ prefixXor ] ; NEW_LINE Even [ prefixXor ] += 1 ; NEW_LINE DEDENT DEDENT return cntSub ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 2 , 2 , 3 , 3 , 6 , 7 , 8 ] ; NEW_LINE N = len ( arr ) ; NEW_LINE print ( cntSubXor ( arr , N ) ) ; NEW_LINE DEDENT