


The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains a single integer, 'N', denoting the number of elements in the array.
The second line of each test case contains 'N' space-separated integers denoting the elements of the array 'ARR'.
For each test case, print a single integer - the total number of sub-arrays with an odd sum.
Print the output of each test case in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^5
1 <= ARR[i] <= 10^4
Where 'T' denotes the number of test cases, 'N' denotes the number of elements in the array, and 'ARR[i]' denotes the 'i'th' element of the array 'ARR'.
Time limit: 1 sec
The approach to this problem will be to check for each sub-array, if the sum of all elements in the sub-array is odd or not. We will use the modulo operator to find the remainder produced when the sum of all sub-array elements is divided by 2. If the remainder is 1, then the sum of all sub-array elements is odd.
You can find the sum of all elements in the subarray from start to end index in the below way:
ARR[start : end] = ARR[0 : end] - ARR[0: start - 1]Therefore, our approach will be to maintain an array PREFIXSUM of size N to store the prefix sum of the array. We will set the variable TOTALSUBARRAYS as 0, which stores the total number of sub-arrays with an odd sum. We will iterate start from 0 to N - 1, and we will find PREFIXSUM[START], which is equal to PREFIXSUM[START - 1] + ARR[START].
Now there will be two cases:
The intuition behind the approach is to observe that the difference between odd and even numbers is an odd number. Similarly, the difference between even and odd numbers is an odd number. You can find the sum of all elements in the subarray from start to end index in the below way:
ARR[start : end] = ARR[0 : end] - ARR[0: start - 1]If ARR[0 : END] is odd, then we need to find ARR[0: START - 1] with even values to obtain ARR[START : END],i.e sum of sub-array from start to end, with odd values. Similarly, If ARR[0 : END] is even, then we need to find ARR[0: START - 1] with odd values to obtain ARR[START : END] with odd values.
Therefore, our approach is to keep track of the total number of the prefix with odd and even sum. We will maintain two variables, EVENPRESUM, and ODDPRESUM, which stores the total number of the prefixes of the array with even and odd sum respectively and we will set both variables as 0. We will set the variable TOTALSUBARRAYS as 0, which stores the total number of sub-arrays with an odd sum. We will iterate START through 0 to N - 1 and find the sum of all elements in the array from 0 to START. Let the obtained value be CURRPRESUM.
Now there will be two cases: