2024-06-16 11:44:08 +02:00
|
|
|
package main
|
2024-05-30 17:57:56 +02:00
|
|
|
|
|
|
|
func countTriplets(arr []int) int {
|
|
|
|
precomputePrefix := func() []int {
|
|
|
|
prefix := append([]int{0}, arr...)
|
|
|
|
|
|
|
|
for i, _ := range arr {
|
|
|
|
prefix[i+1] ^= prefix[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
return prefix
|
|
|
|
}
|
|
|
|
|
|
|
|
prefix := precomputePrefix()
|
|
|
|
|
|
|
|
triplets := 0
|
|
|
|
for left, _ := range prefix {
|
|
|
|
for right := left + 1; right < len(prefix); right++ {
|
|
|
|
if prefix[left] == prefix[right] {
|
|
|
|
triplets += right - left - 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return triplets
|
|
|
|
}
|