I’m working on the silver division guide’s prefix sums, and I tried doing this problem: USACO.

I have made a 2d array whose elements are 1 if there are k-1 layers on that location, and -1 if there are k layers (0 otherwise). But I’m not sure how to optimize for TWO rectangles… (it would take O(200^4)).

Also im not sure, but in a general coordinate problem, from (x1, y1) to (x2, y2), do we let the lattice points themselves take on elements in an array, or unit squares bounded by four lattice points (as probably in this case)?