bzoj2850 Chocolate Kingdom *

Source: Internet
Author: User

bzoj2850 Chocolate Kingdom

Test instructions

n chocolate, each with milk content, cocoa content and tasty value. M individuals, each with three weights a,b,c, if the milk content of a chocolate *a+ cocoa content *b<c can be accepted. Ask everyone to accept the sum of the delicious value of chocolate. n,m≤50000.

Exercises

For all chocolates, the tree node maintains the sum of the subtree's tasty values in addition to maintaining the maximum minimum value of the sub-tree's horizontal ordinate. At the time of the query if the value of the tree's milk content maximum by a + cocoa content maximum *b less than C is the whole subtrees tree can be accepted, otherwise as long as the subtree may have the opportunity to exist acceptable chocolate on the traversal of the subtrees tree.

Code:

1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineInc (I,J,K) for (int i=j;i<=k;i++)5 #defineMAXN 500106 #definell Long Long7 using namespacestd;8 9 inline ll read () {Ten     CharCh=getchar (); ll f=1, x=0; One      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} A      while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); -     returnf*x; - } the intN,m,f,rt; ll ans; - structp{intpos[2],v;BOOL operator< (ConstP &a)Const{returnpos[f]<a.pos[f];}} PS[MAXN]; - structNd{p POS;intmx[2],mn[2],LC,RC; ll SM;} NDS[MAXN]; - BOOLCheckintAintB,ll c,ll d,ll e) {returnc*a+d*b<e;} + voidUpdateintx) { -Inc (I,0,1){ +         if(NDS[X].LC) Ands[x].mx[i]=Max (Nds[x].mx[i],nds[nds[x].lc].mx[i]), atnds[x].mn[i]=min (nds[x].mn[i],nds[nds[x].lc].mn[i]); -         if(nds[x].rc) -nds[x].mx[i]=Max (Nds[x].mx[i],nds[nds[x].rc].mx[i]), -nds[x].mn[i]=min (nds[x].mn[i],nds[nds[x].rc].mn[i]); -     } -     if(NDS[X].LC) nds[x].sm+=Nds[nds[x].lc].sm; in     if(nds[x].rc) nds[x].sm+=Nds[nds[x].rc].sm; - } to intBuildintLintRintNow ) { +F=now;intMid= (l+r) >>1; Nth_element (ps+l,ps+mid,ps+r+1); -Inc (I,0,1) Nds[mid].mx[i]=nds[mid].mn[i]=ps[mid].pos[i]; NDS[MID].SM=PS[MID].V; nds[mid].pos=Ps[mid]; the     if(L<mid) Nds[mid].lc=build (l,mid-1, now^1);if(mid<r) Nds[mid].rc=build (mid+1, r,now^1); *Update (mid);returnmid; $ }Panax Notoginseng int Get(intx,ll a,ll b,ll c) { -     intq=0; theQ+=check (nds[x].mx[0],nds[x].mx[1],A,B,C); Q+=check (nds[x].mx[0],nds[x].mn[1],a,b,c); +Q+=check (nds[x].mn[0],nds[x].mx[1],A,B,C); Q+=check (nds[x].mn[0],nds[x].mn[1],a,b,c); A     returnQ; the } + voidQueryintx,ll a,ll b,ll c) { -     if(Check (nds[x].pos.pos[0],nds[x].pos.pos[1],A,B,C)) ans+=nds[x].pos.v;intDl=0, dr=0; $     if(NDS[X].LC) dl=Get(NDS[X].LC,A,B,C);if(nds[x].rc) dr=Get(nds[x].rc,a,b,c); $     if(dl==4) Ans+=nds[nds[x].lc].sm;Else if(DL) query (NDS[X].LC,A,B,C); -     if(dr==4) Ans+=nds[nds[x].rc].sm;Else if(DR) query (NDS[X].RC,A,B,C); - } the intMain () { -N=read (); M=read (); Inc (I,1, N) ps[i].pos[0]=read (), ps[i].pos[1]=read (), Ps[i].v=read (); Rt=build (1N0);WuyiInc (I,1, M) { thell X=read (), Y=read (), Z=read (); ans=0; Query (RT,X,Y,Z); printf"%lld\n", ans); -     } Wu     return 0; -}

20160906

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.