1. 程式人生 > >bzoj 1568 [JSOI2008]Blue Mary開公司 超哥線段樹

bzoj 1568 [JSOI2008]Blue Mary開公司 超哥線段樹

提示 sdi out digi sin 最大 zoj mst borde

[JSOI2008]Blue Mary開公司

Time Limit: 15 Sec Memory Limit: 162 MB
Submit: 1808 Solved: 639
[Submit][Status][Discuss]

Description

技術分享圖片

Input

第一行 :一個整數N ,表示方案和詢問的總數。 接下來N行,每行開頭一個單詞“Query”或“Project”。 若單詞為Query,則後接一個整數T,表示Blue Mary詢問第T天的最大收益。 若單詞為Project,則後接兩個實數S,P,表示該種設計方案第一天的收益S,以及以後每天比上一天多出的收益P。 1 <= N <= 100000 1 <= T <=50000 0 < P < 100,| S | <= 10^6 提示:本題讀寫數據量可能相當巨大,請選手註意選擇高效的文件讀寫方式。

Output

對於每一個Query,輸出一個整數,表示詢問的答案,並精確到整百元(以百元為單位,

例如:該天最大收益為210或290時,均應該輸出2)。沒有方案時回答詢問要輸出0

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

HINT

題解:可以看出許多條一次函數,然後每次詢問的時候就是求一個x的坐標的答

   案,超哥線段樹可以說就是永久標記維護各段的最大值。

    技術分享圖片

 1 #include<cstring>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<iostream>
 5 #include<cmath>
 6 #include<queue>
 7 #include<map>
 8 
 9 #define N 50007
10 #define ls p<<1
11 #define rs p<<1|1
12
using namespace std; 13 inline int read() 14 { 15 int x=0,f=1;char ch=getchar(); 16 while(!isdigit(ch)){if(ch==-)f=-1;ch=getchar();} 17 while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-0;ch=getchar();} 18 return x*f; 19 } 20 21 int n,tot; 22 double ans; 23 int tr[N<<2]; 24 char ch[20]; 25 struct Node 26 { 27 double k,b; 28 }a[N<<1]; 29 30 bool judge(int x,int y,int t) 31 { 32 t--; 33 return a[x].b+a[x].k*t>a[y].b+a[y].k*t; 34 } 35 void ins(int p,int l,int r,int x) 36 { 37 if (l==r) 38 { 39 if (judge(x,tr[p],l)) tr[p]=x; 40 return; 41 } 42 int mid=(l+r)>>1; 43 if (a[x].k>a[tr[p]].k) 44 { 45 if (judge(x,tr[p],mid)) ins(ls,l,mid,tr[p]),tr[p]=x; 46 else ins(rs,mid+1,r,x); 47 } 48 else 49 { 50 if (judge(x,tr[p],mid)) ins(rs,mid+1,r,tr[p]),tr[p]=x; 51 else ins(ls,l,mid,x); 52 } 53 } 54 void query(int p,int l,int r,int x) 55 { 56 ans=max(ans,a[tr[p]].k*(x-1)+a[tr[p]].b); 57 if (l==r) return; 58 int mid=(l+r)>>1; 59 if (x<=mid) query(ls,l,mid,x); 60 else query(rs,mid+1,r,x); 61 } 62 int main() 63 { 64 n=read(); 65 for (int i=1;i<=n;i++) 66 { 67 scanf("%s",ch); 68 if (ch[0]==P) 69 { 70 tot++; 71 scanf("%lf%lf",&a[tot].b,&a[tot].k); 72 ins(1,1,n,tot); 73 } 74 else 75 { 76 ans=0;query(1,1,n,read()); 77 printf("%d\n",(int)ans/100); 78 } 79 } 80 }

bzoj 1568 [JSOI2008]Blue Mary開公司 超哥線段樹