Solution
讨论版误导我好久
[li,ri]确实是闭区间,但是温度是可以取实数的,比如
1 2 100 300 200
2 3 300 100 200
ans=600 取2.5
所以我们保存坐标的时候需要保存li与ri+0.5
剩下的事情,就是排序+二分+前缀和的运用了
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
#define db double
using namespace std;
int n,v,cas,tot;
int a[50005],b[50005],c[50005];
double t[100005];
ll now,ans,s;
struct ty
{
db d;
int id;
ll sa,sb,sc;
}L[50005],R[50005];
bool cmp1(ty x,ty y)
{
return x.d>y.d;
}
bool cmp2(ty x,ty y)
{
return x.d<y.d;
}
int erfen1(int l,int r,db x)
{
if(l>r) return r;
int mid=(l+r)/2;
if(x>=L[mid].d) return erfen1(l,mid-1,x); else return erfen1(mid+1,r,x);
}
int erfen2(int l,int r,db x)
{
if(l>r) return r;
int mid=(l+r)/2;
if(x>R[mid].d) return erfen2(mid+1,r,x); else return erfen2(l,mid-1,x);
}
int main()
{
cin>>cas;
while(cas--)
{
cin>>n;
tot=0;ans=0;s=0;
for(int i=1;i<=n;i++)
{
scanf("%lf%lf%d%d%d",&L[i].d,&R[i].d,&a[i],&b[i],&c[i]);
L[i].id=i;
R[i].id=i;
tot++;
t[tot]=L[i].d;
tot++;
t[tot]=R[i].d+0.5;
s=s+a[i];
}
sort(t+1,t+tot+1);
sort(L+1,L+n+1,cmp1);
sort(R+1,R+n+1,cmp2);
for(int i=1;i<=n;i++)
{
v=L[i].id;
L[i].sa=L[i-1].sa+a[v];
L[i].sb=L[i-1].sb+b[v];
L[i].sc=L[i-1].sc+c[v];
v=R[i].id;
R[i].sa=R[i-1].sa+a[v];
R[i].sb=R[i-1].sb+b[v];
R[i].sc=R[i-1].sc+c[v];
}
for(int i=1;i<=tot;i++)
{
v=erfen1(1,n,t[i]);
now=s-L[v].sa+L[v].sc;
v=erfen2(1,n,t[i]);
now=now-R[v].sa+R[v].sb;
ans=max(ans,now);
}
ans=max(ans,L[n].sc);
printf("%I64d\n",ans);
}
return 0;
}