Lotus and Horticulture
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 289 Accepted Submission(s): 86
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.__
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] .
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
思路:一开始想到用前缀和处理,但是一看1e9,没往下想。今天正好学了一下离散化。
这个就是离散化+前缀和就可以了。
不过值得注意的是,上面说了温度可以是任意实数,那么我们如果考虑到所有的情况的化,就是距离每个区间端点0.5的点了,这时候这个点既不在当前区间内,也不在后面那个区间内。
一开始数组开小了显示一直wa,(PД`q。)·。'゜的一声就哭了不应该rte么
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e5+7;
int n,m;
struct node
{
int l,r;
long long mid,low,high;
}p[50005];
long long ans[MAXN];
map<int,int>q;
map<int,int>::iterator it;
int main()
{
int i;
int t;
scanf("%d",&t);
while(t--)
{
q.clear();
scanf("%d",&n);
for(i=0;i<n;++i)
{
scanf("%d%d%I64d%I64d%I64d",&p[i].l,&p[i].r,&p[i].mid,&p[i].high,&p[i].low);
p[i].l<<=1;
p[i].r=p[i].r<<1|1;
if(!q[p[i].l])q[p[i].l]=1;
if(!q[p[i].r])q[p[i].r]=1;
}
//标号
int cnt=2;
it=q.begin();
for(;it!=q.end();it++)
{
it->second=cnt++;
}
//处理前缀和
for(i=1;i<cnt;++i)ans[i]=0;
for(i=0;i<n;++i)
{
int l=p[i].l;
int r=p[i].r;
long long low=p[i].low;
long long mid=p[i].mid;
long long high=p[i].high;
ans[1]+=low;
ans[q[l]]+=mid-low;
ans[q[r]]+=high-mid;
}
//得到当前爱的总值,更新答案
long long MAX=0;
for(i=1;i<cnt;++i)
{
ans[i]+=ans[i-1];
MAX=max(MAX,ans[i]);
}
printf("%I64d\n",MAX);
}
return 0;
}