题目大意:
给你一个长方体,让你求这个长方体可以圈住的点的最小权值和;
思路:
首先枚举x坐标,找出区间长度不超过la的区间;
然后限定y坐标,当其区间长度在所给范围内则加上相应数值,若超过了则减去相应数值。
最后限定z坐标,使得更新的区间长度恰好等于所给的范围;
#include<bits/stdc++.h>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int maxn=1009;
const int N=5009;
int mx[N<<2],tag[N<<2];
int la,lb,lc;
struct node
{
int x,y,z,v;
} num[maxn];
int cmp1(node a,node b)
{
return a.x<b.x;
}
struct line
{
int x,l,r,v;
line(int a,int b,int c,int d)
{
x=a,l=b,r=c,v=d;
}
};
int cmp2(line a,line b)
{
if(a.x!=b.x)
return a.x<b.x;
return a.v>b.v;
}
int pushup(int rt)
{
mx[rt]=max(mx[rt<<1],mx[rt<<1|1]);
}
int pushdown(int rt)
{
if(tag[rt])
{
tag[rt<<1]+=tag[rt];
tag[rt<<1|1]+=tag[rt];
mx[rt<<1]+=tag[rt];
mx[rt<<1|1]+=tag[rt];
tag[rt]=0;
}
}
void build(int l,int r,int rt)
{
tag[rt]=0;
mx[rt]=0;
if(l<r)
{
int m=l+r>>1;
build(lson);
build(rson);
}
}
void update(int L,int R,int v,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
tag[rt]+=v;
mx[rt]+=v;
return;
}
pushdown(rt);
int m=l+r>>1;
if(L<=m)
update(L,R,v,lson);
if(m<R)
update(L,R,v,rson);
pushup(rt);
}
int cal(int a,int b)
{
vector<line> t;
for(int i=a; i<=b; i++)
{
int tx=num[i].y,ty=num[i].z,tz=num[i].v;
t.push_back(line(tx,ty,ty+lc,tz));
t.push_back(line(tx+lb,ty,ty+lc,-tz));
}
sort(t.begin(),t.end(),cmp2);
build(0,N,1);
int mxm=-0x3f3f3f3f;
for(int i=0; i<t.size(); i++)
{
update(t[i].l,t[i].r,t[i].v,0,N,1);
mxm=max(mxm,mx[1]);
}
return mxm;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int x,y,z,v;
int cnt=0;
for(int i=1; i<=n; i++)
{
scanf("%d%d%d%d",&x,&y,&z,&v);
if(v<0)
{
num[cnt].x=x+1000;
num[cnt].y=y+1000;
num[cnt].z=z+1000;
num[cnt++].v=-v;
}
}
scanf("%d%d%d",&la,&lb,&lc);
if(cnt==0)
{
puts("Error 404, mahou shoujo not found!");
continue;
}
sort(num,num+cnt,cmp1);
int mm=0;
for(int i=0,j=0; i<cnt&&j<cnt;)
{
while(j<cnt&&num[j].x-num[i].x<=la) j++;
mm=max(mm,cal(i,j-1));
while(i+1<cnt&&num[i+1].x==num[i].x) i++;
i++;
}
printf("%d\n",-mm);
}
return 0;
}
/*3
1 2 3 -9
1 6 7 -1
3 4 2 -4
2 2 4
*/