1568: [JSOI2008]Blue Mary开公司
Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 715 Solved: 240
[ Submit][ Status][ Discuss]
Description
Input
第一行 :一个整数N ,表示方案和询问的总数。 接下来N行,每行开头一个单词“Query”或“Project”。 若单词为Query,则后接一个整数T,表示Blue Mary询问第T天的最大收益。 若单词为Project,则后接两个实数S,P,表示该种设计方案第一天的收益S,以及以后每天比上一天多出的收益P。
Output
对于每一个Query,输出一个整数,表示询问的答案,并精确到整百元(以百元为单位,例如:该天最大收益为210或290时,均应该输出2)。
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
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
0
0
0
0
HINT
约定: 1 <= N <= 100000 1 <= T <=50000 0 < P < 100,| S | <= 10^6 提示:本题读写数据量可能相当巨大,请选手注意选择高效的文件读写方式。
Source
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<bitset>
#include<algorithm>
#include<cstring>
#include<map>
#include<stack>
#include<set>
#include<cmath>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;
const int maxn = 5E4 + 10;
typedef double DB;
DB k[maxn*20],b[maxn*20];
int n;
char com[20];
void Insert(int o,int l,int r,DB K,DB B)
{
DB A1 = K*(DB)(l) + B,A2 = k[o]*(DB)(l) + b[o];
DB B1 = K*(DB)(r) + B,B2 = k[o]*(DB)(r) + b[o];
if (A1 > A2 && B1 > B2) {k[o] = K; b[o] = B; return;}
if (A1 < A2 && B1 < B2) return;
if (l == r) return;
DB x = (b[o] - B)/(K - k[o]);
int mid = (l + r) >> 1;
if (x <= mid) {
if (A1 > A2) Insert(2*o,l,mid,K,B);
else Insert(2*o,l,mid,k[o],b[o]),k[o] = K,b[o] = B;
}
else {
if (A1 > A2) Insert(2*o+1,mid+1,r,k[o],b[o]),k[o] = K,b[o] = B;
else Insert(2*o+1,mid+1,r,K,B);
}
}
DB Query(int o,int l,int r,int pos)
{
DB ret = k[o]*(DB)(pos) + b[o];
if (l == r) return ret;
int mid = (l + r) >> 1;
if (pos <= mid) ret = max(ret,Query(2*o,l,mid,pos));
else ret = max(ret,Query(2*o+1,mid+1,r,pos));
return ret;
}
int main()
{
#ifdef DMC
freopen("Corporation2.in","r",stdin);
#endif
cin >> n;
while (n--) {
scanf("%s",com);
if (com[0] == 'P') {
DB K,B; scanf("%lf%lf",&B,&K);
Insert(1,0,maxn,K,B);
}
else {
int x; scanf("%d",&x); --x;
DB ans = Query(1,1,maxn,x);
ans /= 100.00; int Ans = ans;
printf("%d\n",Ans);
}
}
return 0;
}