Question: Calculate the coverage area for n matrices.
Thought: I read others' answer reports
Given the coordinates in the lower left corner of a rectangle and the coordinates in the upper right corner are respectively: (x1, y1) and (x2, y2). For such a rectangle, we construct two line segments, one positioned in x1, in the y coordinate, the range is [y1, y2], and the value of a cover domain is 1. The other line segment is located in x2, And the range is [y1, y2], given a cover value of-1. Based on this method, two line segments are constructed for each rectangle, and all line segments are sorted from left to right based on the located x.
# Include
# Include
# Include
# Include using namespace std; # define M 100 # define inf 0x3fffffff # define maxn 500000*2 struct seg {int flag; double up, down, x ;} line [M * 5]; int cmp (seg a, seg B) {return. x
= R | tree [id]. up <= l) return 0; if (tree [id]. flag) {if (tree [id]. cover> 0) // Recursion to the leaf node {double temp_x = tree [id]. x; double ans = (x-temp_x) * (tree [id]. up-tree [id]. down); tree [id]. x = x; // locate the last xtree [id]. cover + = flag; return ans;} else {tree [id]. cover + = flag; tree [id]. x = x; return 0 ;}} double ans1, ans2; ans1 = insert (id * 2, x, l, r, flag ); ans2 = insert (id * 2 + 1, x, l, r, flag); return ans1 + ans2;} int main () {int t, ca = 1; while (scanf ("% d", & t) {double x1, x2, y1, y2; int k = 0; for (int I = 0; I