1442.cpp (447B)
1 class Solution { 2 public: 3 int countTriplets(const vector<int> &arr) { 4 static int left[301]; 5 left[0] = 0; 6 int n = arr.size(), res = 0; 7 8 for (int i = 0, acc = 0; i < n; i++) 9 left[i + 1] = acc ^= arr[i]; 10 11 for (int i = 0; i < n; i++) { 12 for (int j = i + 1; j < n; j++) { 13 if (left[i] == left[j + 1]) res += j - i; 14 } 15 } 16 17 return res; 18 } 19 };