Bzoj2850 Chocolate Kingdom

Source: Internet
Author: User

Time limit:60 Sec Memory limit:512 MB
submit:505 solved:204 Chocolate in the description chocolate Kingdom is made of milk and cocoa. But not every piece of chocolate is popular with the people of the kingdom, because people don't like chocolate that is too sweet. For each piece of chocolate, we set X and Y as their milk and cocoa content. Since everyone has their own standard of sweetness, everyone has two parameters A and B, respectively, for his own definition of milk and cocoa weight, so the milk and cocoa content of x and Y, respectively, the chocolate for his sweet degree is ax + by. And everyone has a sweet limit c, all the sweetness of the chocolate is greater than or equal to C he is not acceptable. Each piece of chocolate has a delicious value H. Now we want to know the sum of the delicious value of the chocolate that he can accept for everyone. Input the first line two positive integers n and M, respectively, the number of chocolates and the number of queries. Next n lines, three integers per line, x,y,h, meaning as shown in the title. Next m line, three integers per line a,b,c, meaning as shown in the title.

Output m line, where line I represents the sum of the delicious value of the chocolate that the person I can accept.

Sample Input3 3
1 2 5
3 1 4
2 2 1
2 1 6
1 3 5
1 3 7Sample Output5
0
4HINT

1 <= N, M <= 50000,1 <= 10^9,-10^9 <= A, B, X, y <= 10^9.

Source

Violet 0

K-d Tree

Optimize queries by ax+by valuations with x and y coordinates

1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <queue>6 using namespacestd;7 Const intmxn=100010;8 intRead () {9     intx=0, f=1;CharCh=GetChar ();Ten      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} One      while(ch>='0'&& ch<='9') {x=x*Ten-'0'+ch;ch=GetChar ();} A     returnx*F; - } - structnode{ the     intmax[2],min[2]; -     intL,r; -     intd[2],v; -     Long Longsum; + }T[MXN]; - intNowd=0; + intcmpConstNode A,ConstNode B) { A     return(A.d[nowd]<b.d[nowd] | | (A.d[nowd]==b.d[nowd] && a.d[nowd^1]<b.d[nowd^1])); at } - introot,nct=0; - intn,m; - Long Longa,b,c,ans=0;  - voidPushup (intRtintx) { -t[rt].max[0]=max (t[rt].max[0],t[x].max[0]); int[rt].max[1]=max (t[rt].max[1],t[x].max[1]); -t[rt].min[0]=min (t[rt].min[0],t[x].min[0]); tot[rt].min[1]=min (t[rt].min[1],t[x].min[1]); +     return;  - } the intBuild (intLintRintD) { *Nowd=D; $     intMid= (l+r) >>1;Panax NotoginsengNth_element (t+l,t+mid,t+r+1, CMP); -t[mid].max[0]=t[mid].min[0]=t[mid].d[0]; thet[mid].max[1]=t[mid].min[1]=t[mid].d[1]; +     if(L!=mid) {T[mid].l=build (l,mid-1, d^1);p ushup (MID,T[MID].L);} A     if(R!=mid) {T[mid].r=build (mid+1, r,d^1);p ushup (MID,T[MID].R);} thet[mid].sum=t[t[mid].l].sum+t[t[mid].r].sum+t[mid].v; +     returnmid; - } $InlineBOOLPdLong LongXLong LongY) {return(a*x+b*y<c);} $ intCntintRT) { -     intres=0; -     if(PD (t[rt].max[0],t[rt].max[1])) res++; the     if(PD (t[rt].min[0],t[rt].max[1])) res++; -     if(PD (t[rt].max[0],t[rt].min[1])) res++;Wuyi     if(PD (t[rt].min[0],t[rt].min[1])) res++; the     returnRes; - } Wu voidQueryintRT) { -     if(PD (t[rt].d[0],t[rt].d[1])) ans+=t[rt].v; About     intL=0, r=0; $     if(T[RT].L) L=CNT (T[RT].L); -     if(T[RT].R) R=CNT (T[RT].R); -     if(l==4) {ans+=t[t[rt].l].sum;}//and I have to count R so I can't return . -         Else if(L) query (T[RT].L); A     if(r==4) {ans+=T[t[rt].r].sum;}  +         Else if(R) query (T[RT].R); the     return; - } $ intMain () { theN=read (); m=read (); the     inti,j; the      for(i=1; i<=n;i++){ thet[i].d[0]=read (); t[i].d[1]=read (); t[i].v=read (); -     } inRoot=build (1N0); the      for(i=1; i<=m;i++){ theA=read (); B=read (); c=read (); Aboutans=0; the query (root); theprintf"%lld\n", ans); the     } +     return 0; -}

Bzoj2850 Chocolate Kingdom

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.