【bzoj1568】[JSOI2008]Blue Mary开公司

1568: [JSOI2008]Blue Mary开公司

Time Limit: 15 Sec   Memory Limit: 162 MB
Submit: 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

Sample Output

0
0
0
0
0

HINT

Source

[ Submit][ Status][ Discuss]




超哥线段树模板

用到了一种标记永久化的方法

考虑以x轴建一棵线段树

对于线段树上的每一个节点,存的是当前节点区间[L , R]内,与mid相交的最上面的那一个直线

每次插入一条直线,我们考虑将新直线和当前直线比较

每次舍弃劣的一段,递归到儿子插入可能产生优解的一段直线

然后一通瞎搞

PS.这题的最大利益至少得是0。。。。。因为这个蒟蒻WA了好几遍。。。。

代码:
#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;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值