hdu 6012 维护区间前缀和

Lotus and Horticulture

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 192    Accepted Submission(s): 67


Problem Description
These days Lotus is interested in cultivating potted plants, so she wants to build a greenhouse to meet her research desires.

Lotus placed all of the  n  pots in the new greenhouse, so all potted plants were in the same environment.

Each plant has an optimal growth temperature range of  [l,r] , which grows best at this temperature range, but does not necessarily provide the best research value (Lotus thinks that researching poorly developed potted plants are also of great research value).

Lotus has carried out a number of experiments and found that if the growth temperature of the i-th plant is suitable, it can provide  ai  units of research value; if the growth temperature exceeds the upper limit of the suitable temperature, it can provide the  bi  units of research value; temperatures below the lower limit of the appropriate temperature, can provide  ci  units of research value.

Now, through experimentation, Lotus has known the appropriate growth temperature range for each plant, and the values of  a b c  are also known. You need to choose a temperature for the greenhouse based on these information, providing Lotus with the maximum research value.

__NOTICE: the temperature can be any real number.__
 

Input
The input includes multiple test cases. The first line contains a single integer  T , the number of test cases.

The first line of each test case contains a single integer  n[1,50000] , the number of potted plants.

The next  n  line, each line contains five integers  li,ri,ai,bi,ci[1,109] .
 

Output
For each test case, print one line of one single integer presenting the answer.
 

Sample Input
  
  
1 5 5 8 16 20 12 10 16 3 13 13 8 11 13 1 11 7 9 6 17 5 2 11 20 8 5
 

Sample Output
  
  
83




#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <cstdio>
using namespace std;
/*
题意:
给一些区间范围,在区间左中右有不同的值,要找一个点使得总值最大,给出总值

//http://blog.csdn.net/mengxiang000000/article/details/54650271解释得很好

当取的点包括区间左端点和右端点右边0.5的点,这样可以包含所有的答案种类,
先把区间扩大两倍,直接取整数点----端点OR端点左右1的点
显然接下来要对所有可以选的点离散化.
当选负无穷,答案是所有c的和,考虑此时向右移动,答案怎么变化
每次达到一个区间X的左端点,答案加上a-c,

*/
typedef long long ll;
const int maxn = 50000*2 + 5;//每个区间有两个端点,记得要翻倍
int t, n;
struct node {
	int x;//坐标
	int del;//变化值
}qq[maxn];
int cmp(node a, node b)
{
	return a.x < b.x;
}
int l, r, a, b, c;//等于,大于,小于
ll sum = 0;
int cnt = 0;

void solve()
{
	int now = 1;
	ll ans = sum;
	sort(qq + 1, qq + cnt + 1, cmp);
	for (int i = 1; i <= cnt; i++)  //遍历所有位置
	{
		while (now <= cnt && qq[now].x == qq[i].x)
			sum += qq[now++].del;
		ans = max(ans, sum);
	}
	printf("%I64d\n", ans);
}
int main()
{
	scanf("%d", &t);
	while (t--)
	{
		sum = 0;
		cnt = 0;
		scanf("%d", &n);
		for (int i = 0; i < n; i++)
		{
			scanf("%d%d%d%d%d", &l, &r, &a, &b, &c);
			l *= 2; r *= 2;
			sum += c;  //负无穷的和
			qq[++cnt].x = l;  qq[cnt].del = -c + a;
			qq[++cnt].x = r+1;  qq[cnt].del = -a + b;
		}
		solve();
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值