1568: [JSOI2008]Blue Mary开公司
Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 1491 Solved: 508
[ 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
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
Source
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long LL;
typedef long double DL;
const int INF = 2147483647;
const int maxn = 4 * 500100;
char s[20];
int n,m;
DL k[maxn],b[maxn];
inline LL getint()
{
LL ret = 0,f = 1;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
ret = ret * 10 + c - '0',c = getchar();
return ret * f;
}
inline void insert(int o,int l,int r,DL kx,DL bx)
{
int mid = l + r >> 1;
DL xx = (mid - 1) * kx + bx,xo = (mid - 1) * k[o] + b[o];
if (l == r){if (xx > xo) k[o] = kx , b[o] = bx; return;}
int lc = o << 1,rc = o << 1 | 1;
if (xx < xo)
{
if (kx < k[o]) insert(lc,l,mid,kx,bx);
else insert(rc,mid + 1,r,kx,bx);
}
else
{
if (kx < k[o]) insert(rc,mid + 1,r,k[o],b[o]);
else insert(lc,l,mid,k[o],b[o]);
k[o] = kx; b[o] = bx;
}
}
inline DL query(int o,int l,int r,int pos)
{
DL ret = k[o] * (pos - 1) + b[o];
if (l == r) return ret;
int mid = l + r >> 1,lc = o << 1,rc = o << 1 | 1;
if (pos <= mid) ret = max(ret,query(lc,l,mid,pos));
else ret = max(ret,query(rc,mid + 1,r,pos));
return ret;
}
int main()
{
n = getint();
bool tmp = 1;
for (int i = 1; i <= n; i++)
{
scanf("%s",s);
if (!strcmp(s,"Project"))
{
DL kx,bx;
scanf("%Lf%Lf",&bx,&kx);
insert(1,1,500000,kx,bx);
tmp = 0;
}
else
{
int pos = getint();
DL ans = query(1,1,500000,pos);
ans /= 100;
printf("%d\n",(int)ans);
}
}
return 0;
}