#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
const int N=2000010;
LL s[N];
LL b[N],bp[N];
int A,B,C,m;
struct Op{
int x1,x2,y1,y2,z1,z2,c;
}op[N];
int get(int i,int j,int k)
{
return ((i-1)*B+j-1)*C+k;
}
void insert(LL b[],int x1,int x2,int y1,int y2,int z1,int z2,int c)
{
b[get(x1, y1, z1) ] +=c;
b[get(x1, y1, z2+1)] -=c;
b[get(x1, y2+1, z1) ] -=c;
b[get(x1, y2+1, z2+1)] +=c;
b[get(x2+1,y1, z1) ] -=c;
b[get(x2+1,y1, z2+1)] +=c;
b[get(x2+1,y2+1, z1) ] +=c;
b[get(x2+1,y2+1, z2+1)] -=c;
}
bool check(int t)
{
memcpy(bp,b,sizeof bp);
for(int i=1;i<=t;i++) insert(bp,op[i].x1,op[i].x2,op[i].y1,op[i].y2,op[i].z1,op[i].z2,op[i].c);
for(int i=1;i<=A;i++)
for(int j=1;j<=B;j++)
for(int k=1;k<=C;k++)
{
bp[get(i,j,k)]+=bp[get(i, j, k-1)];
bp[get(i,j,k)]+=bp[get(i, j-1, k) ];
bp[get(i,j,k)]-=bp[get(i, j-1, k-1)];
bp[get(i,j,k)]+=bp[get(i-1, j, k) ];
bp[get(i,j,k)]-=bp[get(i-1, j, k-1)];
bp[get(i,j,k)]-=bp[get(i-1, j-1, k) ];
bp[get(i,j,k)]+=bp[get(i-1, j-1, k-1)];
if(bp[get(i,j,k)]<0) return true;
}
return false;
}
int main()
{
scanf("%d%d%d%d",&A,&B,&C,&m);
for(int i=1;i<=A;i++)
for(int j=1;j<=B;j++)
for(int k=1;k<=C;k++)
{
scanf("%lld",&s[get(i,j,k)]);
insert(b,i,i,j,j,k,k,s[get(i,j,k)]);
}
for(int i=1;i<=m;i++)
{
int x1,x2,y1,y2,z1,z2,c;
scanf("%d%d%d%d%d%d%d",&x1,&x2,&y1,&y2,&z1,&z2,&c);
op[i]={x1,x2,y1,y2,z1,z2,-1*c};
}
int l=1,r=m;
while(l<r)
{
int mid=l+r>>1;
if(check(mid)) r=mid;
else l=mid+1;
}
printf("%d",l);
return 0;
}
这里的前缀和计算方法是啥意思?
为啥不是
???
get函数会导致数组越界
有没有case呀
易懂hh %%%