Simple Counting
If we we have an alternating sequence of size n that ends at i, it adds n alternating subarrays:\n\n[1, 0, 1, 0, 1]\n   [0, 1, 0, 1]\n      [1, 0, 1]\n\t     [0
If we we have an alternating sequence of size `n` that ends at `i`, it adds `n` alternating subarrays:\n```\n[1, 0, 1, 0, 1]\n   [0, 1, 0, 1]\n      [1, 0, 1]\n\t     [0, 1]\n\t        [1]\n```\nFor `i + 1`, we extend our sequence, and add its size to the result.\n\nEach time we find a repeated value, we have to start a new sequence (with size `1`).\n\n**C++**\n```cpp\nlong long countAlternatingSubarrays(vector<int>& nums) {\n    long long res = 1, size = 1;\n    for (int i = 1; i < nums.size(); ++i) {\n        size = nums[i - 1] == nums[i] ? 1 : size + 1;\n        res += size;\n    }\n    return res;\n}\n```
['C']