Bob and Cakes

0

0 votes
, Data Structures, Math, Basic Math, Arrays
Problem

Bob likes cakes very much and at the same time he is very health conscious.
In his village, there is a party going on where they have arranged N cakes in a row and each cake has a nutritious value ai associated with it. If the nutritious value of any cake is 0 then Bob will fall sick after eating that cake.
Bob is very strict about how he eats his cakes, he will select a range [l,r] and then start eating all the cakes in that range including l and r
So in how many ways Bob can choose [l,r] such that he doesn't fall sick

Input :

The first line contains T , the number of test cases.

For each test case :

The first line contains N, the number of cakes in the row.

The next line contain N integers, ai the nutritious value of the ith cake.

Output:

For each test case, print an integer value : the number of ways in which Bob can select a range [l,r] where lr

Note : The value may not fit in a 32-bit integer

Constraints : 

1T103

1N105

109ai109

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

The cakes with index 1,2,4,5 are nutritious and Bob will not fall sick after eating them

There are 6 ways in which Bob can select a subarray - {1,1}, {2,2},{4,4},{5,5},{1,2},{4,5}

Editor Image

?