Investigating Zeroes and Ones
InterviewTime limit0.5sMemory limit1024 MB
Count the contiguous subarrays of a binary array that contain an odd number of ones, with N up to 10^5.
- Level
Easy3 of 10
- Topics
- Prefix sum, Math
- Solved
- No attempts yet
Problem
You are in a mysterious binary world where an array of binary digits is waiting for you. Each digit is either 0 or 1, and together they form a distinct pattern. Your task is to count the subarrays that contain an odd number of ones.
The array is . A subarray is a segment of consecutive elements. For example, the subarrays of are , , , , , and . Count the subarrays that contain an odd number of ones. The answer may not fit in a 32-bit integer.
Input
The first line contains an integer (), the length of the binary sequence.
The second line contains binary digits ().
Output
Print a single line containing the number of subarrays that have an odd number of ones.