Editorial for BSSPC '21 S4 - Child Prodigy Chadstin
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
We observe the matrix can be compressed  times if and only if 
 and 
 are multiples of 
, and the edges of the outline formed from all the rectangles are at multiples of 
 on the grid.
Therefore, we use a 2D difference array to compute the state of the binary matrix, then brute force all the row and column positions where the matrix changes value. The answer is the largest  such that 
 divides all of these positions and the dimensions of the grid.
Time complexity: 
Subtask 2
We apply the solution from the previous subtask, but with coordinate compression.
Time complexity: 
Subtask 3
We can efficiently compute the edge positions by doing line sweep across the rectangles with a lazy segment tree supporting range increment and range minimum query operations. We sweep each dimension independently, using the segment tree to maintain the number of overlapping rectangles in the other dimension. Any rectangle edge causing the number of overlapping rectangles at a point to change from  to 
 or 
 to 
 is an edge we need to consider. We can check this with an RMQ before each event.
Time complexity: 
Subtask 4
We apply the solution from the previous subtask, but with coordinate compression.
Time complexity: 
Comments