8
int rectangleArea(vector<vector<int>> &rectangles) {9
map<int, vector<Point>> lines; // y -> array of Points10
for (auto &r : rectangles) {16
lines[y1].push_back(Point{x1, +1});17
lines[y1].push_back(Point{x2, -1});18
lines[y2].push_back(Point{x1, -1});19
lines[y2].push_back(Point{x2, +1});26
map<int, int> scanline; // x -> delta27
for (const auto &[y, points] : lines) {28
area += (y - prevy) * (long)length;30
// Update scanline for new y: add new rectanhgles,32
for (auto point : points) {33
auto xdelta = scanline.find(point.X);34
if (xdelta != end(scanline)) {35
xdelta->second += point.delta;36
if (xdelta->second == 0) scanline.erase(xdelta);38
scanline[point.X] = point.delta;41
// For current y-line calc the length of42
// intersection with rectangles46
for (const auto &[x, delta] : scanline) {47
int oldcount = rectCount;51
else if (rectCount == 0)55
if (rectCount > 0) length += scanline.rbegin()->first - startX;60
return area % (1000000007);