"BZOJ-1568" Blue Mary opens company Li Chao line segment tree (tag is persistent)

Source: Internet
Author: User

1568: [Jsoi2008]blue Mary Open Company time limit:15 Sec Memory limit:162 MB
submit:557 solved:192
[Submit] [Status] [Discuss] Description

Input

First line: An integer n that represents the total number of scenarios and queries. Next n lines, each line starts with a word "Query" or "Project". If the word is query, then an integer t is followed, indicating that Blue Mary asks for the maximum benefit of the T-day. If the word is Project, then two real s,p are followed, indicating the first day of the design of the proceeds s, and the next day more than the last day of earnings P.

Output

For each query, output an integer that represents the answer to the query and is accurate to the whole hundred (in hundred units, for example: The maximum gain for the day is 210 or 290, should be output 2).

Sample Input10
Project 5.10200 0.65000
Project 2.76200 1.43000
Query 4
Query 2
Project 3.80200 1.17000
Query 2
Query 3
Query 1
Project 4.58200 0.91000
Project 5.36200 0.39000Sample Output0
0
0
0
0HINT

Convention: 1 <= N <= 100000 1 <= T <=50000 0 < P < 100,| S | <= 10^6 Tip: The volume of reading and writing data may be quite large, please note that players choose efficient way to read and write files.

SourceSolution

Li Chao segment tree, for Insert, equivalent to insert in root, tag permanent, that is, Mark is not pushed, each point mark is unique

When inserting a new line, judging the current interval, that is, the intersection of the horizontal axis, in order to determine the dominant range, their own understanding:

As for the query, because it looks down, so there will be no impact, complexity $o (LOGN) $

Maybe personal understanding is wrong, welcome to guide

Code
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>using namespacestd;intRead () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9') {if(ch=='-') f=-1; Ch=GetChar ();}  while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;}intn,m;structlinenode{DoubleK,b;intID; Linenode (intx0=0,inty0=0,intx1=0,inty1=0,intId=0) {ID=ID; if(x0==x1) k=0, b=Max (y0,y1); ElseK= (Double) (y0-y1)/(X0-X1), b= (Double) y0-k*x0; }     DoubleGETF (intx) {returnk*x+b;}};BOOLCMP (Linenode A,linenode B,intx) {    if(! a.ID)return 1; returnA.GETF (x)!=b.getf (x)? A.GETF (x) <b.getf (x):a.id<b.id;//The value of the comparison value line, A and b at x, if A<b returns 1}#defineMAXN 50010Linenode TREE[MAXN<<2]; Linenode Query (intNowintLintRintx) {    if(L==R)returnTree[now]; intMid= (l+r) >>1;    Linenode tmp; if(X<=mid) Tmp=query (now<<1, l,mid,x); ElseTmp=query (now<<1|1, mid+1, r,x); returnCMP (TREE[NOW],TMP,X)?Tmp:tree[now];}voidInsertintNowintLintR,linenode x) {    if(!tree[now].id) tree[now]=x; if(CMP (tree[now],x,l)) swap (tree[now],x); if(L==r | | tree[now].k==x.k)return; intMid= (l+r) >>1;Doublex= (tree[now].b-x.b)/(X.K-TREE[NOW].K);//find the intersection, X is the intersection axis, judge the interval    if(X<l | | X&GT;R)return; if(x<=mid) Insert (now<<1, L,mid,tree[now]), tree[now]=x; ElseInsert (now<<1|1, mid+1, r,x);}voidInsert (intNowintLintRintLintR,linenode x) {    if(L<=l && r>=r) {Insert (NOW,L,R,X);return;} intMid= (l+r) >>1; if(L<=mid) Insert (now<<1, l,mid,l,r,x); if(R>mid) Insert (now<<1|1, mid+1, r,l,r,x);} intMain () {M=read (); n=50000; Charopt[ the];  while(m--) {scanf ("%s", opt); if(opt[0]=='P')                 {                    DoubleK,b; scanf"%LF%LF",&k,&c); Linenode tmp; TMP.K=b; Tmp.b=k-b; Tmp.id=1; Insert (1,1N1, n,tmp); }            intx; if(opt[0]=='Q') X=read (), printf ("%lld\n",(Long Long) (Query (1,1, n,x). GETF (x)/ -+1e-8)); }    return 0;}

Reference to Zky Seniors template dozen ... There are a lot of problems in the middle, and they are very similar (cover face)

"BZOJ-1568" Blue Mary opens company Li Chao line segment tree (tag is persistent)

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.