#P1222. Union Area of Right Isosceles Triangles
Union Area of Right Isosceles Triangles
Union Area of Right Isosceles Triangles
You are given n right isosceles triangles on the plane. Each triangle is described by three integers \(x, y, m\). The vertices of a triangle are \((x,y)\), \((x+m,y)\) and \((x,y+m)\).
Your task is to compute the total area covered by these triangles (i.e. the area of their union). Note that triangles can overlap.
The area of an individual triangle is \(\frac{1}{2}m^2\), but overlapping parts should only be counted once in the union.
One efficient approach is to use a line sweep along the x-axis. For a vertical line at x = \(c\), each triangle that spans this x-coordinate contributes an interval of y values, which can be merged to compute the overall y-length covered at x = \(c\). Integrate these y-lengths over x to get the area.
inputFormat
The first line contains an integer \(n\) indicating the number of triangles. Each of the following \(n\) lines contains three integers \(x\), \(y\), \(m\) describing one triangle.
It is guaranteed that the input values are such that the union area can be computed accurately.
outputFormat
Output a single number representing the total area covered by the given triangles. The answer will be considered correct if it has an absolute or relative error of at most \(10^{-6}\).
sample
1
0 0 1
0.5