BZOJ2850 Chocolate Kingdom

Source: Internet
Author: User

Test instructions: Given a heap of points, each point has the right value, each time in the line $ax + by + C = 0$ The weight of the point and

KD Tree maintain the point right in the two-dimensional interval and just fine ... Build complexity $o (n * logn) $, one-time query time $o (\sqrt{n}) $

1 /**************************************************************2 problem:28503 User:rausen4 language:c++5 result:accepted6 time:15568 Ms7 memory:4220 KB8 ****************************************************************/9  Ten#include <cstdio> One#include <algorithm> A   - using namespacestd; -typedefLong Longll; the Const intN = 5e4 +5; -   -Inlineintread (); -   + intN, M; - intA, B, C, D; +   A structPoint { at     intx[2], V; -       - Point () {} -       -Inlinevoid Get() { -x[0] = Read (), x[1] = read (), V =read (); in     } -       to     int&operator[] (inti) { +         returnX[i]; -     } theInlineBOOL operator< (ConstPoint &p)Const { *         returnX[D] <P.x[d]; $     }Panax Notoginseng } P[n]; -   theInlineBOOLCheckintXinty) { +     returnA * x + B * Y <C; A } the   + structKd_tree { -Kd_tree *ls, *rs; $ Point p; $     intmn[2], mx[2]; - ll sum; -       the Kd_tree () { -ls = rs =NULL;Wuyip =Point (); thesum =0; -     } Wu       -     #defineLen (1 << 16) AboutInlinevoid*operator New(size_t) { $         StaticKd_tree *mempool, *C; -         if(Mempool = =c) -Mempool = (c =NewKd_tree[len]) +Len; -*c =Kd_tree (); A         returnC++; +     } the     #undefLen -       $InlineintCalc () { the         returnCheck (mn[0], mn[1]) + Check (mn[0], mx[1]) + Check (mx[0], mn[1]) + Check (mx[0], mx[1]); the     } the       theInlinevoidUpdate () { -         Static inti; in          for(i =0; I <2; ++i) { theMn[i] = Mx[i] =P[i]; the             if(LS) { AboutMn[i] = min (mn[i], LS-mn[i]); theMx[i] = max (mx[i], LS-mx[i]); the             } the             if(RS) { +Mn[i] = min (Mn[i], RS-mn[i]); -Mx[i] = max (Mx[i], RS-mx[i]); the             }Bayi         } thesum =p.v; the         if(ls) sum + = lssum; -         if(rs) Sum + = rs-sum; -     } the        the     #defineMid (L + R >> 1) the     voidBuildintLintRintNow, point *P) { theD =Now ; -Nth_element (P + L, p + Mid, p + r +1); thep =P[mid]; the         if(L <mid) { thels =New() Kd_tree;94LS-to build (L, mid-1, !Now , P); the         } the         if(Mid <r) { thers =New() Kd_tree;98RS-Build (Mid +1R!Now , P); About         } - update ();101     }102     #undefMid103      104 ll query () { thell res =0;106         intcntl, cntr;107         if(Check (p[0], p[1]) Res + =p.v;108         if(LS) {109CNTL = ls-Calc (); the             if(Cntl = =4) Res + = ls-sum;111             Else if(cntl) Res + = ls-query (); the         }113         if(RS) { theCntr = RSCalc (); the             if(Cntr = =4) Res + = RS-sum; the             Else if(cntr) Res + = RS-query ();117         }118         returnRes;119     } -} *T;121  122 intMain () {123     inti;124n = Read (), M =read (); the      for(i =1; I <= N; ++i)126P[i].Get();127T =New() Kd_tree; -T-Build (1N0, p);129      while(m--) { theA = Read (), B = Read (), C =read ();131printf"%lld\n", T-query ()); the     }133     return 0;134 }135  136InlineintRead () {137     Static intx, SGN;138     Static Charch;139x =0, SGN =1, ch =GetChar (); $      while(Ch <'0'||'9'<ch) {141         if(ch = ='-') SGN =-1;142CH =GetChar ();143     }144      while('0'<= CH && Ch <='9') {145x = x *Ten+ CH-'0';146CH =GetChar ();147     }148     returnSGN *x;149}
View Code

BZOJ2850 Chocolate Kingdom

Related Article

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.