Obtain a rectangle that covers more than K times with the image watermark (11983) and

Source: Internet
Author: User

K is very small, and each storage can overwrite 0 ~ K-times interval and K-times or more are all K-times. You can create a template.

View code

# Include <cstdio> # Include <Cstring> # Include <Algorithm> Using   Namespace  STD; typedef  Long   Long  LLD;  # Define Lson L, M, RT <1 # Define Rson m + 1, R, RT <1 | 1 Const  Int Maxn = 60000  ;  Int Sum [maxn < 2 ] [ 15  ];  Int Cov [maxn < 2  ];  Int  X [maxn];  Int  N, m;  Struct  SEG { Int  L, R, h;  Int  Flag; seg () {} seg (  Int _ L, Int _ R, Int _ H, Int  _ Flag): L (_ L), R (_ r), H (_ H), flag (_ flag ){}  Bool   Operator <( Const SEG & CMP) Const  { Return H < CMP. h ;}} ss [maxn];  Void Pushup ( Int RT, Int L, Int  R ){  If (COV [RT]> = M | L = R) {memset (sum [RT],  0 , Sizeof  (Sum [RT]);  Int T = cov [RT] <m?Cov [RT]: m; sum [RT] [T] = X [R + 1 ]- X [l];  Return  ;}  Int  I;  For (I = 0 ; I <cov [RT]; I ++) sum [RT] [I] = 0  ;  For (I = cov [RT]; I <m; I ++ ) Sum [RT] [I] = Sum [RT < 1 ] [I-cov [RT] + sum [RT < 1 | 1 ] [I- Cov [RT]; sum [RT] [m] = 0  ;  For (I = m-cov [RT]; I <= m; I ++ ) Sum [RT] [m] + = Sum [RT < 1 ] [I] + sum [RT < 1 | 1  ] [I];}  Void Build ( Int L,Int R, Int  RT) {cov [RT] = 0 ; Sum [RT] [ 0 ] = X [R + 1 ]- X [l];  For ( Int I = 1 ; I <= m; I ++) sum [RT] [I] = 0  ;  If (L = r) Return ;  Int M = (L + r)> 1  ; Build (lson); Build (rson );}  Void Update ( Int L, Int R, Int Val, Int L, Int R, Int  RT ){  If (L <= L & R <= R) {cov [RT] + = Val; pushup (RT, L, R );  Return  ;}  Int M = (L + r)> 1  ;  If (L <= M) Update (L, R, Val, lson );  If (R> M) Update (L, R, Val, rson); pushup (RT, L, R );}  Int  Main (){  Int T, CA = 1 , I, J, K, x1, x2, Y1, Y2; scanf (  "  % D  " ,& T );  While (T -- ) {Scanf (  "  % D  " , & N ,& M );  Int TOT = 0  ;  For (I =1 ; I <= N; I ++ ) {Scanf (  "  % D  " , & X1, & Y1, & X2, & Y2); x2 ++; Y2 ++ ; X [tot] = X1; SS [tot ++] = Seg (x1, x2, Y1, 1  ); X [tot] = X2; SS [tot ++] = Seg (x1, x2, Y2 ,- 1  );} Sort (x, x +TOT); sort (SS, SS + TOT );  Int Nx = unique (x, x + ToT )- X; build (  0 , NX- 1 , 1 ); //  Printf ("% d \ n", sum [1] [0]); LLD ans = 0  ;  For (I = 0 ; I <tot- 1 ; I ++ ){  Int Left = lower_bound (x, x + NX, ss [I]. L )- X;  Int Right = lower_bound (x, x + NX, ss [I]. R)-X- 1  ; Update (left, right, ss [I]. Flag,  0 , NX- 1 , 1  ); Ans + = (LLD) sum [ 1 ] [M] * (LLD) (ss [I + 1 ]. H-Ss [I]. H);} printf (  "  Case % d: % LLD \ n  " , CA ++ , ANS );}  Return   0  ;} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.