I have a binary matrix of size M*N. I'm given K queries where each consists of given sub-matrix, with upper left coord (x1,y1) and lower right coord (x2,y2). My task is to find how many one's are in each submatrix. I should find the best solution in terms of time complexity.
How can I achieve that?
I suppose that I should somehow pre-calculate the matrix to I can then answer the queries in O(1) time. But I'm not really sure how to pre-calculate the matrix.