Even subarrays

4

8 votes
Counting and Arrangements, Dynamic Programming, Algorithms
Problem

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

1T20000

1N200000

1Ai1e9i[1,N]

Sum of N over all test cases does not exceed 200000

Sample Input
1
4
3 5 2 3
Sample Output
6
Time Limit: 1
Memory Limit: 256
Source Limit:
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

Editor Image

?