[JSOI2008] Blue Mary opens the company

Source: Internet
Author: User

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.
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.

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).
Answer ask to output 0 when there is no plan

Sample Input
10
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.39000

Sample Output
0
0
0
0
0

To write this topic, we need to use the tag of the segment tree to perpetuate it. So what is the tagging of line-segment trees permanent?
The so-called permanent, refers to the line of the tree is not next to the mark, then every time I ask the leaves to the root of the path of information processing under the good.
No sign of the next pass? What's the use?
There are many useful things, such as a small constant, or a topic that cannot be maintained when the tag is passed, so that it can be permanently tagged.

What about the problem? It is a token permanent, but not absolute.
First, the project can be seen as a straight line, then the problem is converted to insert n straight line, and then ask the X position of the largest Y.

Each time a line is added, it is first judged by the slope of the line (recorded in mid) and the line that is recorded in the interval, and then to determine which line is better at the mid point.

If the slope of the big answer is better, then in (Mid,r], it must be a large slope of the answer excellent, so we just need to lower the slope of the line to the left son, and the current interval recorded straight line to the slope of a large line, if the slope of the small answer is better, then in [L,mid] must be a smaller slope , so we're going to pass the big slope straight to the right son. Recursive update, the current interval is also updated

In fact, there should be a small problem to read here, because the segment tree is recorded on a segment of the polyline, and the slope of these lines must increment. After we have updated the answer to the interval record in one of the lines mentioned above, we put the other line down, is the other side not to be delegated? Or, the current record of the new line, not on the other side of the delegation, judge, update it?

The question of marking permanence inevitably has a solution. When we counted the answers, we counted all the straight lines passing by, updating the answers, and there would be no problem.

Or maybe we change our mind, the line recorded in each interval is just the best line in the mid, so our problem is solved.

#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include < Algorithm> #define INF 0x7f7f7f7fusing namespace std;typedef long long ll;typedef unsigned int ui;typedef unsigned long    Long Ull;inline int read () {int X=0,f=1;char ch=getchar (); for (;ch< ' 0 ' | |    Ch> ' 9 '; Ch=getchar ()) if (ch== '-') f=-1;    for (; ch>= ' 0 ' &&ch<= ' 9 '; Ch=getchar ()) x= (x<<1) + (x<<3) +ch-' 0 '; return x*f;}    inline void print (int x) {if (x>=10) print (X/10); Putchar (x%10+ ' 0 ');}  const int n=1e5,day=5e4;double k[n+10],b[n+10];  K is the slope, B is the intersection with the y-axis (from junior high school math destruction) int lazy[n*4+10]; Mark record is not slope, is ordinal char s[10]; #define LS (p<<1) #define RS (p<<1|1) bool Check (int x,int y,int cnt) {return k[x]* ( cnt-1) +b[x]>k[y]* (cnt-1) +b[y];}        Two straight lines at the CNT point determine void change (int p,int l,int R,int t) {if (l==r) {if (check (t,lazy[p],l)) lazy[p]=t;    Return    } int mid= (L+R) >>1; if (K[t]>k[lazy[p]]) {//will be judged against the preceding text description to be very clear if (check (T,LAZY[P],MID)) change (Ls,l,mid,lazy[p]), lazy[p]=t;    else change (rs,mid+1,r,t);        } if (K[t]<k[lazy[p]]) {if (check (t,lazy[p],mid)) change (Rs,mid+1,r,lazy[p]), lazy[p]=t;    else change (ls,l,mid,t); }}double get (int x,int cnt) {return k[x]* (cnt-1) +b[x];}    Get the answer to the CNT point double query (int p,int l,int R,int t) {if (l==r) return get (lazy[p],t);    int mid= (L+R) >>1;  Double Ans=get (lazy[p],t);    Update the answer if (t<=mid) Ans=max (Ans,query (ls,l,mid,t));    if (t>mid) Ans=max (Ans,query (rs,mid+1,r,t)); return ans;}    int main () {int n=read (), cnt=0;        for (int i=1;i<=n;i++) {scanf ("%s", s+1);            if (s[1]== ' P ') {cnt++;            scanf ("%lf%lf", &b[cnt],&k[cnt]);  Change (1,1,DAY,CNT);            The title does not tell you the definite number of days, so you can only play it this way} if (s[1]== ' Q ') {int x=read ();            Double T=query (1,1,day,x);  printf ("%d\n", (int) t/100); Output}} return 0, as required by the title;}

[jsoi2008]blue Mary Open Company

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.