Problem 3212 · Medium

Count Submatrices With Equal Frequency of X and Y

Every submatrix that contains the top-left cell is a prefix rectangle, so two prefix-count tables give its X and Y counts in constant time.

Open the interactive visualisation