#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 2000010;
typedef long long LL;
LL b[N],bp[N];//差分数组
LL s[N];//原数组
int A, B, C, m;
int op[N/2][7];//操作,x1,x2,y1,y2,z1,z2,c
int get(int i, int j, int k)
{
return (i*B + j)*C + k;
}
void insert(LL b[],int x1,int x2, int y1,int y2, int z1, int z2,int c)
{
//求差分数组,从前面的点开始
b[get(x1, y1, z2 + 1 )] -= c;
b[get(x1, y1, z1 )] += c;
b[get(x1, y2 + 1,z2 + 1 )] += c;
b[get(x1, y2 + 1,z1 )] -= c;
b[get(x2 + 1,y1, z2 + 1 )] += c;
b[get(x2 + 1,y1, z1 )] -= c;
b[get(x2 + 1,y2 + 1,z2 + 1 )] -= c;
b[get(x2 + 1,y2 + 1,z1 )] += c;
}
bool check(int t)
{
memcpy(bp, b, sizeof bp);
for (int i = 1; i <= t; i ++ )//操作
insert(bp,op[i][0],op[i][1],op[i][2],op[i][3],op[i][4],op[i][5],-op[i][6]);//要负数
//求前缀和,从后面的点开始
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-1, j, k )];
bp[get(i,j,k)] += bp[get(i, j-1,k )];
bp[get(i,j,k)] += bp[get(i, 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, k-1)];
bp[get(i,j,k)] -= bp[get(i, j-1,k-1)];
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 ++ )
for (int j = 0; j < 7; j ++ )
scanf("%d", &op[i][j]);
int l = 1, r = m;
while (l < r)
{
int mid = l + r >> 1;
if (check(mid)) r = mid;
else l = mid + 1;
}
printf("%d\n",r);
return 0;
}
请问那个坐标转换那个为什么是 (i*B+j) * C+k 呢