← 返回 bytedance 的题目列表Count Alternating-Parity Subarrays
类型:online_judge
Problem: Count Alternating-Parity Subarrays
Given an integer array a of length n, count how many contiguous subarrays satisfy:
Length 1 subarrays always qualify.
For length > 1, every adjacent pair has different parity (one odd, one even).
Return the total number of such subarrays.
Input (one common OA format)
Line 1: integer n
Line 2: n integers
Output
A single integer: the number of qualifying subarrays.
Constraints
1 <= n <= 2e5
|a[i]| <= 1e9
Example
Input
4
1 2 3 4
Output
10