#P4750. Satellite Photo Union Area
Satellite Photo Union Area
Satellite Photo Union Area
A satellite is surveying a possible rover landing area on the moon. The landing area is modeled as a square grid embedded in the standard coordinate system.
The satellite has taken n photos, each capturing a square area of the surface. Careful camera calibration has ensured that all photos are aligned with the grid — all four vertices have integer coordinates. There are two types of photos:
- Photos of type
A
have sides parallel to the coordinate axes. Such a photo is specified by giving the integer coordinates (x, y) of the square’s center and the length of its side a (always an even integer). The area of such a photo is a2. - Photos of type
B
have sides at a 45° angle to the coordinate axes. Such a photo is specified by giving the integer coordinates (x, y) of the square’s center and the length of its diagonal d (always an even integer). The area of such a photo is \(\frac{d^2}{2}\).
Note that different photos may overlap. Your task is to compute the total surface area that is covered by at least one photo.
Input format: The first line contains an integer n indicating the number of photos. Each of the next n lines describes one photo. A line begins with a character A
or B
indicating the type, followed by three integers. In a type A
photo the three numbers denote x, y and a. In a type B
photo they denote x, y and d. You may assume that a and d are even integers, and that the four vertices of each photo have integer coordinates.
inputFormat
The input begins with a line containing an integer n (the number of photos). This is followed by n lines, each describing a photo in one of the two formats:
A x y a
— for a photo of type A.B x y d
— for a photo of type B.
It is guaranteed that all provided values are integers and that a and d are even.
outputFormat
Output a single integer representing the total surface area covered by the union of all satellite photos.
sample
1
A 0 0 4
16