1568: [Jsoi2008]blue Mary Open Company time limit:15 Sec Memory limit:162 MB
submit:602 solved:214
[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.
A special line-segment tree ...
1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 Const intmaxn=50010;6 structnode{7 Doubleb;8Node (Doublea_=0.0,Doubleb_=0.0){9a=a_;b=b_;Ten } One DoubleVal (intp) { A returna*p+b; - } - intCmP (intLintR,node x) { the if(Val (L) >=x.val (L) &&val (R) >=x.val (R))return 1; - if(Val (L) <=x.val (L) &&val (R) <=x.val (R))return-1; - return 0; - } +}t[maxn<<2]; - + DoubleQuery (intXintLintRintg) { A if(L==R)returnT[x]. Val (l); at intMid= (l+r) >>1; - Doubleret=T[x]. Val (g); - if(mid>=g)returnMax (Ret,query (x<<1, L,mid,g)); - Else returnMax (Ret,query (x<<1|1, mid+1, R,g)); - } - in voidModify (intXintLintR,node P) { - inttmp=p.cmp (l,r,t[x]); to if(tmp==1) t[x]=p; + if(tmp!=0)return; - intMid= (l+r) >>1; the *tmp=p.cmp (l,mid,t[x]); $ if(tmp!=1&&L!=R) Modify (x<<1, l,mid,t[x]);Panax Notoginseng if(tmp!=-1&&L!=R) Modify (x<<1, l,mid,p); -TMP=P.CMP (mid+1, r,t[x]); the if(tmp!=1&&L!=R) Modify (x<<1|1, mid+1, r,t[x]); + if(tmp!=-1&&L!=R) Modify (x<<1|1, mid+1, r,p); A } the + Charop[Ten]; - intMain () { $ intq,p,n=50000; $ Doubles,t; -scanf"%d",&Q); - while(q--){ thescanf"%s", op); - if(!STRCMP (OP,"Project")){Wuyiscanf"%LF%LF",&s,&t); theModify (1,1, N,node (t,s-t)); - } Wu Else{ -scanf"%d",&p); Aboutprintf"%d\n",(int) (Query (1,1, n,p)/ -)); $ } - } -}
Data structure (line segment tree): Bzoj 1568 [jsoi2008]blue Mary Open Company