res to store the total number of submatrices with all ones.height to store the histogram heights for each column.height array for the current row.
b. Initialize a stack to keep track of indices of non-decreasing heights.
c. Iterate over each column in the current row:
i. While the stack is not empty and the current height is less than the height at the top of the stack, pop from the stack.
ii. Calculate the number of submatrices using the current height and the widths determined by the stack.
iii. Push the current index and the cumulative number of submatrices onto the stack.
d. Add the cumulative number of submatrices to res.res as the final result.