Let's say we have given matrix of size $N \cdot M$, only with zeros and ones. For each element in the matrix, we want to count subrectangles that are covering this element and are made only of zeros. We actually want only the sum of those value, not separately for each of them.
010 -> 201 001 -> 320 The sum is: 3 + 2 + 2 + 1 = 8
I have a solution with complexity of $O(N^3)$ which counts all possible rectangles with fixing the lower right corner, but I know that this can be improved somehow to $O(N^2)$