#B4287. Painted Rectangles Area
Painted Rectangles Area
Painted Rectangles Area
You are given n rectangles on a wall. The ith rectangle is specified by its bottom‐left coordinate \( (x_{1}, y_{1}) \) and top‐right coordinate \( (x_{2}, y_{2}) \). Note that the rectangles may overlap. Your task is to compute the total area that needs to be painted, counting overlapping regions only once.
Input Format: The first line contains an integer \( n \) representing the number of rectangles. Each of the next \( n \) lines contains four integers: \( x_{1}\), \( y_{1}\), \( x_{2}\), and \( y_{2} \) where \( x_{1} < x_{2} \) and \( y_{1} < y_{2} \).
Example: For \( n = 2 \) with the two rectangles specified by \( (2, 2, 9, 5) \) and \( (6, 1, 12, 9) \), the total painted area is \( 60 \).
inputFormat
The first line contains a single integer \( n \) — the number of rectangles. Each of the following \( n \) lines contains four space-separated integers \( x_{1} \), \( y_{1} \), \( x_{2} \), \( y_{2} \), representing the bottom-left and top-right coordinates of a rectangle.
outputFormat
Output a single integer representing the total painted area of the rectangles, where overlapping regions are counted only once.
sample
2
2 2 9 5
6 1 12 9
60