Even subarrays
Practice
4 (8 votes)
Counting and arrangements
Dynamic programming
Algorithms
Problem
91% Success 1826 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array \(A\) containing \(N\) elements. Your task is to find the number of subarrays with even products.
A subarray of an array can be obtained by deleting any prefixes and suffixes.
Input format
- The first line contains an integer \(T\) denoting the number of test cases.
- The first line of each test case contains an integer \(N\) denoting the number of elements in array \(A\).
- The second line of each test case contains \(N\) space-separated integers of array \(A\).
Output format
For each test case, print a single line denoting subarrays with even products.
Constraints
\(1 \leq T \leq 20000\)
\(1 \leq N \leq 200000\)
\(1 \leq A_i \leq 1e9 \forall i \in [1,N]\)
Sum of \(N\) over all test cases does not exceed 200000
Sample Input
1 4 3 5 2 3
Sample Output
6
Explanation
Subarrays with even sum:
[2],[5,2],[2,3],[3,5,2],[5,2,3],[3,5,2,3]
These are 6 in total
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Submissions
Please login to view your submissions
Similar Problems
Points:20
4 votes
Tags:
MathematicsOpenApprovedEasyNumber Theory
Points:20
Tags:
Easy
Points:20
2 votes
Tags:
Counting and ArrangementsDynamic ProgrammingAlgorithmsBasics of Greedy Algorithms
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor