Easy two line solution 
Intuitionif the current bit is alternate then it can contribute in each subarray so add the length of the current subarray.ApproachComplexity
Time complexity: O
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
if the current bit is alternate then it can contribute in each subarray so add the length of the current subarray.
# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(n)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
    #define ll long long
public:
    long long countAlternatingSubarrays(vector<int>& nums) {
        vector<ll>dp(nums.size());
        ll sum=1;
        dp[0]=1;
        for(int i=1;i<nums.size();i++){
            if(nums[i]^nums[i-1]==1)dp[i]=dp[i-1]+1;
            else dp[i]=1;
            sum+=dp[i];
        }
     return sum;
    }
};
```
['C++']