Given a set of $n$ rectangles $[a, b] × [c, d]$ in a cartesian coordinate plane, calculate the area of their union.
My first thought of this problem is by using a simple sweep line algorithm plus a segment tree. However i could not get any idea to design such a segment tree that works. Any idea?
I also have another version of this problem, that is to find the area of all regions that are covered by exactly $k$ rectangles.