RECTQUER - Editorial

Someone please help me find why all my solution to this problem throw verdict “SIGSEGV” :’( I used the same logic as mentioned in the editorial.

of number d in (x1,y1)-(x2,y2) = S[x2][y2]–S[x2][y1-1]–S[x1-1][y2]+S[x1-1][y1-1]

can someone explain this??

You may look at the figure. It is based on inclusion-exclusion principle actually. But it is straightforward in the picture.

Nope, here S[][], is a prefix matrix of binary matrix for a given number.d. Please read the editorial step by step. We first divide the original problem into D parts (D is the number of different numbers in the original matrix, at most 10).