Valentine's gift: Satakshi And Roses

4.4

5 votes
Medium-Hard
Problem

As you all know, Valentine's day just passed. Here is a small incident from that day.

Mr. A wanted to ask her crush Satakshi out on a date. Before that he wants to impress her.

For that, he has a rectangular shaped garden with N x M blocks. Each block has some number of roses in it. All the roses in a block are united and hence cannot be separated.

Mr.A can impress her crush by selecting a sub-rectangle in the garden such that the total sum of number of roses in it is >= L and <= R. He will then gift this to her. He needs your help in counting the number of ways to do that. Will you help him?

Input Format:

First line contains T, the number of test cases.
First line of each test case contains two integers N and M.
Second line contains two integers L and R.
Next N lines, each contains M integers, where A[i][j] = number of roses in corresponding block.

Output Format:

For each test case, print the number of ways to find a sub-rectangle in the garden such that number of roses in it >= L and <= R.

Constraints:

1 <= T <= 3

1 <= N , M <= 250

1 <= A[i][j] <= 100

1 <= L <= R <= N * M * max(A[i][j])

Author : Sumeet Varma

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?