Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals…
- User
Given a set of axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
Constraints
Assistant
def main(): import sys input = sys.stdin.read().split() idx = 0 N = int(input[idx]) idx += 1 # Initialize difference array D = [[0] * 1001 for _ in range(1001)] for _ in range(N): x1 = int(input[idx]) y1 = int(input[idx+1]) x2 = int(input[idx+2]) y2 = int(input[idx+3]) idx +=4 # Update the difference array D[x1][y1] += 1 D[x1][y2] -= 1 D[x2][y1] -= 1 D[x2][y2] += 1 # Compute row-wise prefix sums for i in range(1001): for j in range(1, 1001): D[i][j] += D[i][j-1] # Compute column-wise prefix sums for j in range(1001): for i in range(1, 1001): D[i][j] += D[i-1][j] # Find maximum in the 1000x1000 grid max_overlap = 0 for i in range(1000): for j in range(1000): if D[i][j] > max_overlap: max_overlap = D[i][j] print(max_overlap) if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.