human
Count triplet of indices ( i , j , k ) such that XOR of elements between [ i , j ) equals [ j , k ] | Function return the count of triplets having subarray XOR equal.
XOR value till i.
Count and ways array as defined above.
Using the formula stated.
Increase the frequency of x.
Add i + 1 to ways [ x ] for upcoming indices.
Driver code"
Solution in Python:
assistant
#Here is code to count triplet of indices ( i , j , k ) such that XOR of elements between [ i , j ) equals [ j , k ] and the other steps required.
 def CountOfTriplets ( a , n ) :
	answer = 0
	x = 0
	count = [ 0 for i in range ( 100005 ) ]
	ways = [ 0 for i in range ( 100005 ) ]
	for i in range ( n ) :
		x ^= a [ i ]
		answer += count [ x ] * i - ways [ x ]
		count [ x ] += 1
		ways [ x ] += ( i + 1 )
	return answer
if __name__ == ' _ _ main _ _ ' :
	Arr = [ 3 , 6 , 12 , 8 , 6 , 2 , 1 , 5 ]
	N = len ( Arr )
	print ( CountOfTriplets ( Arr , N ) )