Bzoj 1568: [Jsoi2008]blue Mary opens company (Super Brother Line tree)

Source: Internet
Author: User

1568: [Jsoi2008]blue Mary Open Company time limit:15 Sec Memory limit:162 MB
submit:1080 solved:379
[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. 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, outputs an integer that represents the answer to the query and is accurate to the whole hundred dollars (in hundred units,

For example, if the maximum yield for the day is 210 or 290, the output should be 2). Answer when no solution is asked to output 0Sample 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 Source

The template problem of the super-brother line tree.

The super-brother line tree is a segment tree that processes a function,

In the Super Brother line tree, each node holds a number corresponding to a function,

And how did he keep it?

Borrow a picture of a great God

Yes, that's it.

Then for each insert operation,

We go to recursion the value of the node that is small at the current value may be in a larger direction than the value of a large node ....

#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <bitset > #define LS k<<1#define rs k<<1|1using namespace std;const int maxn=1000001;inline void read (int &n) {C Har c= ' + '; int x=0;bool flag=0;while (c< ' 0 ' | | C> ' 9 ') {C=getchar (); if (c== '-') flag=1;} while (c>= ' 0 ' &&c<= ' 9 ') {x=x*10+ (c-48); C=getchar ();} n=flag==1?-x:x;} struct funtion{double k,b;} a[maxn];//record each segment int tree[maxn];//the number of segments that correspond to each node int tot=0;//The total number of line segments inline int pd (int now,int will,int day) {--day;retur n a[now].k*day+a[now].b>a[will].k*day+a[will].b;} inline void Insert (int k,int l,int r,int now) {if (l==r) {if (PD (NOW,TREE[K],L)) Tree[k]=now;return;} int mid= (L+R) >>1;if (A[NOW].K&GT;A[TREE[K]].K)//The slope of the current point is greater than the slope of the target point {if (PD (NOW,TREE[K],MID)) Insert (Ls,l,mid,tree [K]), Tree[k]=now;elseinsert (Rs,mid+1,r,now);} Else{if (PD (NOW,TREE[K],MID)) insert (Rs,mid+1,r,tree[k]), Tree[k]=now;elseinsert (Ls,l,mid,now);}} Double ans=0;void query (int k,int l,int r,int now) {ans=mAx (ans,a[tree[k]].k* (now-1) +a[tree[k]].b), if (l==r) return, int mid= (l+r) >>1;if (now<=mid) query (Ls,l,mid, now); else query (Rs,mid+1,r,now);} int main () {ios::sync_with_stdio (0); int n;cin>>n;for (int i=1;i<=n;i++) {string opt;cin>>opt;if (Opt[0] = = ' P ') {++tot;cin>>a[tot].b>>a[tot].k;insert (1,1,n,tot);} else if (opt[0]== ' Q ') {int p;cin>>p;ans=0;query (1,1,n,p);p rintf ("%d\n", (int) (ans/100));}} return 0;}

  

Bzoj 1568: [Jsoi2008]blue Mary opens company (Super Brother Line tree)

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.