Hdu_3624
This question requires that the volume of the part that covers three or more times be obtained.
If we discretize the zcoordinate, if a part of each layer Z is overwritten by three or more times, it is equivalent to that the projection of this layer Z on the XY plane is covered by three or more times, therefore, for each layer of Z, We can first find the area covered by the projection three or more times, then multiply the height of the layer Z, that is, the layer Z is covered by three or more times.
# Include <stdio. h> # Include < String . H> # Include <Stdlib. h> # Define Maxd 2010 # Define K 3 Int N, m, Z, S, Ty [maxd], TZ [maxd], cover [4 * Maxd] [ 4 ], CNT [ 4 * Maxd]; Struct REC { Int X1, Y1, Z1, X2, Y2, Z2;} rec [maxd]; Struct SEG { Int X, Y1, Y2, Col;} seg [maxd]; Int Cmpint ( Const Void * _ P,Const Void * _ Q ){ Int * P = ( Int *) _ P, * q = ( Int * ) _ Q; Return * P <* Q? - 1 : 1 ;} Int Cmpseg ( Const Void * _ P,Const Void * _ Q) {seg * P = (SEG *) _ p, * q = (SEG * ) _ Q; Return P-> x <q-> X? - 1 : 1 ;} Void Build ( Int Cur, Int X, Int Y ){ Int Mid = (x + y)>1 , Ls = cur < 1 , RS = (cur < 1 ) | 1 ; Memset (cover [cur], 0 , Sizeof (Cover [cur]); cover [cur] [ 0 ] = Ty [Y + 1 ]- Ty [X]; CNT [cur] = 0 ; If (X =Y) Return ; Build (LS, X, mid); Build (RS, mid + 1 , Y );} Void Init (){ Int I, J, K; scanf ( " % D " ,& N ); For (I = 0 ; I <n; I ++) {Scanf ( " % D " , & Rec [I]. x1, & rec [I]. y1, & rec [I]. z1, & rec [I]. x2, & rec [I]. y2 ,& REC [I]. Z2); TZ [I < 1 ] = Rec [I]. Z1, TZ [(I < 1 ) | 1 ] = REC [I]. Z2; ty [I < 1 ] = Rec [I]. Y1, Ty [(I < 1 ) | 1 ] = REC [I]. Y2;} qsort (tz, n < 1 , Sizeof (Tz [ 0 ]), Cmpint); Z =- 1 ; For (I = 0 ; I <(n < 1 ); I ++ ) If (I = 0 | TZ [I]! = TZ [I-1 ]) TZ [ ++ Z] = TZ [I]; qsort (TY, n < 1 , Sizeof (TY [ 0 ]), Cmpint); m =- 1 ; For (I = 0 ; I <(n < 1 ); I ++ ) If (I = 0 | Ty [I]! = Ty [I- 1 ]) Ty [ ++ M] = Ty [I]; build ( 1 , 0 , M- 1 );} Int BS ( Int X ){ Int Mid, min = 0 , Max = m + 1 ; For (;) {Mid = (MAX + min)> 1 ; If (Mid = Min) Break ; If (TY [Mid] <= X) min = Mid; Else Max =Mid ;} Return Mid ;} Void Update ( Int Cur, Int X, Int Y ){ Int Ls = cur < 1 , RS = (cur < 1 ) | 1 ; Memset (cover [cur], 0 ,Sizeof (Cover [cur]); If (CNT [cur]> = K) cover [cur] [k] = Ty [Y + 1 ]- Ty [x]; Else If (X = Y) cover [cur] [CNT [cur] = Ty [Y + 1 ]- Ty [x]; Else { Int I; For (I = CNT [cur]; I <= K; I ++ ) Cover [cur] [I] = Cover [ls] [I-CNT [cur] + cover [RS] [I- CNT [cur]; For (I = k-CNT [cur] + 1 ; I <= K; I ++ ) Cover [cur] [k] + = Cover [ls] [I] + Cover [RS] [I] ;}} Void Refresh ( Int Cur, Int X, Int Y, Int S, Int T, Int C ){ Int Mid = (x + y)> 1 , Ls = cur < 1 , RS = (cur < 1 ) | 1 ; If (X> = S & Y <= T) {CNT [cur] + =C; Update (cur, x, y ); Return ;} If (Mid> = S) Refresh (LS, X, mid, S, T, C ); If (Mid + 1 <= T) Refresh (RS, mid + 1 , Y, S, T, C); Update (cur, x, y );} Void Solve (){ Int I, j, L, R; Long Long Int Ans = 0 , Temp; For (I = 0 ; I <z; I ++ ) {S = 0 ; For (J = 0 ; J <n; j ++ ) If (REC [J]. Z1 <= TZ [I] & rec [J]. Z2> = TZ [I + 1 ]) {Seg [s]. x = Rec [J]. x1, SEG [s]. y1 = rec [J]. y1, SEG [s]. y2 = rec [J]. y2, SEG [s]. col = 1 ; ++ S; seg [s]. x = Rec [J]. x2, SEG [s]. y1 = rec [J]. y1, SEG [s]. y2 = rec [J]. y2, SEG [s]. col =- 1 ; ++ S;} qsort (SEG, S, Sizeof (SEG [ 0 ]), Cmpseg); seg [s]. x = Seg [s- 1 ]. X; temp = 0 ; For (J = 0 ; J <s; j ++ ) {L = BS (SEG [J]. Y1), r = BS (SEG [J]. Y2); refresh ( 1 , 0 , M- 1 , L, R- 1 , SEG [J]. col); temp + = ( Long Long Int ) Cover [ 1 ] [ 3 ] * (SEG [J + 1 ]. X- SEG [J]. X);} ans + = Temp * (tz [I + 1 ]- TZ [I]);} printf ( " % I64d \ n " , ANS );} Int Main (){ Int T, TT; scanf ( " % D " ,& T ); For (Tt = 0 ; TT <t; TT ++ ) {Init (); printf ( " Case % d: " , Tt + 1 ); Solve ();} Return 0 ;}