Posters
Problem Description
There are a lot of posters, each of which is subtracted from a rectangle (which may be totally subtracted). Now we have given the positions of no posters, asking for their area and.
Ensure that the coordinates are between (0, 0) and (50000,500 00. No posters are hashed, and the side of the rectangle subtracted is parallel to the x and Y axes.
Input
There is a lot of data.
For each group of data, the first row has an integer N (0 <N <= 50000), which indicates the number of posters in the next n rows. Each row has eight integers x1, y1, x2, y2, x3, y3, x4, and y4 represent the coordinates in the lower left corner of each poster (x1, y1), the coordinates in the upper right corner (x2, y2), and the coordinates in the upper left corner of the minus rectangle (x3, y3 ), coordinates (x4, y4) (0 <= xi, yi <= 50000 (I = 1... 4) and x1 <= x3 <x4 <= x2, y1 <= y3 <y4 <= y2 ).
The data ends with 0.
Output
Output a row of data in each group, indicating their area and.
Sample Input
2
0 0 10 10 1 1 9 9
2 2 8 8 3 7 7
0
Sample Output
56
This is to divide the rectangle difference into the following forms:
Then perform the rectangular area and:
Remember the size of each array after the problem is converted.
[Cpp]
# Include <cstdio>
# Include <cstring>
# Include <cstdlib>
# Include <cmath>
# Include <cctype>
# Include <iostream>
# Include <functional>
# Include <algorithm>
Using namespace std;
# Define MAXN (50000 + 10)
# Define MAXT (MAXN * 5)
# Define MAXXi (50000 + 10)
# Define Lson (x <1)
# Define Rson (x <1) ^ 1)
Int hpos [MAXN];
Int x [MAXN * 4] = {0 };
Struct SegMent
{
Int x1, x2, h, type;
SegMent (){}
SegMent (int _ x1, int _ x2, int _ h, int _ type): x1 (_ x1), x2 (_ x2), h (_ h ), type (_ type ){}
Friend bool operator <(const SegMent a, const SegMent B) {return a. h <B. h ;}
};
Int n, size;
Struct SegMent_array
{
SegMent a [MAXN * 8];
Int size;
SegMent_array (): size (0)
{
Memset (a, 0, sizeof ());
}
Bool add (int x1, int x2, int y1, int y2)
{
If (x1 = x2 | y1 = y2) return 0;
Else
{
A [++ size] = SegMent (x1, x2, y1, 1 );
A [++ size] = SegMent (x1, x2, y2,-1 );
Return 1;
}
}
};
Struct SegMentTree
{
Long sum [MAXT], cnt [MAXT], len [MAXT];
Int M, n;
Void fillchar (int _ n)
{
N = _ n;
M = 1; while (M-2 <n) M <= 1;
Memset (sum, 0, sizeof (sum ));
Memset (cnt, 0, sizeof (cnt ));
Memset (len, 0, sizeof (len ));
For (int I = M + 1; I <= M + n; I ++) len [I] = x [I-M + 1]-x [I-M];
For (int I = M-1; I> = 1; I --) len [I] = len [I <1] + len [(I <1) ^ 1];
}
Void pushup (int x)
{
Sum [x] = (cnt [x])? (Len [x]) :( (x <M )? (Sum [Lson] + sum [Rson]): 0 );
}
Void update (int x)
{
While (x)
{
Pushup (x); x> = 1;
}
}
Void insert (int l, int r, long c)
{
If (l> r) return;
L = L-1 + M; r = r + 1 + M;
Int ll = l, rr = r;
For (; l ^ r ^ 1; l> = 1, r> = 1)
{
If (~ L & 1) {cnt [l + 1] + = c; pushup (l + 1 );}
If (r & 1) {cnt [r-1] + = c; pushup (r-1 );}
}
// Cout <endl <"Push:" <ll <''<rr <endl;
Update (ll); update (rr );
}
Void print ()
{
For (int I = 1; I <= 2 * M; I ++) if (sum [I]) cout <I <': '<sum [I] <'';
Cout <endl;
For (int I = 1; I <= 2 * M; I ++) if (cnt [I]) cout <I <': '<cnt [I] <'';
Cout <endl;
Cout <endl;
}
} T;
Int main ()
{
// Freopen ("Hdu3265.in", "r", stdin );
While (scanf ("% d", & n )! = EOF)
{
If (n = 0) break;
For (int I = 1; I <= n; I ++)
{
Int x1, y1, x2, y2, x3, y3, x4, y4;
Scanf ("% d", & x1, & y1, & x2, & y2, & x3, & y3, & x4, & y4 );
A. add (x1, x3, y1, y4 );
A. add (x3, x2, y1, y3 );
A. add (x1, x4, y4, y2 );
A. add (x4, x2, y3, y2 );
X [I * 4-3] = x1; x [I * 4-2] = x2; x [I * 4-1] = x3; x [I * 4] = x4;
}
Sort (x + 1, x + 4 * n + 1 );
Size = unique (x + 1, x + 4 * n + 1)-(x + 1 );
/* For (int I = 1; I <= size; I ++) cout <x [I] <'';
Cout <endl;
*/
// Cout <size;
For (int I = 1; I <= size; I ++) hpos [x [I] = I;
T. fillchar (size-1 );
Sort (a. a + 1, a. a + 1 + a. size );
// Cout <'s ';
// For (int I = 1; I <=. size; I ++) cout <. a [I]. x1 <''<. a [I]. x2 <''<. a [I]. h <''<. a [I]. type <endl;
Long ans = 0;
For (int I = 1; I <= a. size; I ++)
{
Ans + = t. sum [1] * (long) a. a [I]. h-a.a [I-1]. h );
T. insert (hpos [a. a [I]. x1], hpos [a. a [I]. x2]-1, a. a [I]. type );
/* Cout <. a [I]. x1 <''<. a [I]. x2 <''<. a [I]. h <''<. a [I]. type <endl;
Cout <ans <endl;
T. print ();
*/}
Cout <ans <endl;
A. size = 0;
}
Return 0;
}