P8666 [蓝桥杯 2018 省 A] 三体攻击 题解
为啥高维借教室比借教室难度评分低啊
为啥都写一维差分啊,来个三维差分。
二分爆炸时间 $x$,考虑怎么 check。
做 $[1,x]$ 的所有操作,然后如果存在一个点受到的攻击量大于这个点的防御力,那么答案 $\le x$,否则答案 $>x$。
用三维差分维护操作,操作结束后判断每个点是否爆炸。
注意 $A\times B\times C\le 10^6$,所以用 vector
开数组即可。
#include <cstdio>
#include <vector>
using namespace std;
struct S
{
int l1, r1, l2, r2, l3, r3, h;
} q[1000050];
int n, l, r, m, A, B, C;
vector<vector<vector<int>>> a, d;
bool P(int x)
{
for (int i = 1; i <= A; ++i)
for (int j = 1; j <= B; ++j)
for (int k = 1; k <= C; ++k)
d[i][j][k] = 0;
for (int i = 1; i <= x; ++i)
{
d[q[i].l1][q[i].l2][q[i].l3] += q[i].h;
d[q[i].l1][q[i].l2][q[i].r3 + 1] -= q[i].h;
d[q[i].l1][q[i].r2 + 1][q[i].l3] -= q[i].h;
d[q[i].l1][q[i].r2 + 1][q[i].r3 + 1] += q[i].h;
d[q[i].r1 + 1][q[i].l2][q[i].l3] -= q[i].h;
d[q[i].r1 + 1][q[i].l2][q[i].r3 + 1] += q[i].h;
d[q[i].r1 + 1][q[i].r2 + 1][q[i].l3] += q[i].h;
d[q[i].r1 + 1][q[i].r2 + 1][q[i].r3 + 1] -= q[i].h;
}
for (int i = 1; i <= A; ++i)
for (int j = 1; j <= B; ++j)
for (int k = 1; k <= C; ++k)
if (a[i][j][k] < (d[i][j][k] += d[i][j][k - 1] + d[i][j - 1][k] - d[i][j - 1][k - 1] + d[i - 1][j][k] - d[i - 1][j][k - 1] - d[i - 1][j - 1][k] + d[i - 1][j - 1][k - 1]))
return 1;
return 0;
}
int main()
{
scanf("%d%d%d%d", &A, &B, &C, &n);
r = n;
a.resize(A + 2);
for (int i = 0; i <= A + 1; ++i)
{
a[i].resize(B + 2);
for (int j = 0; j <= B + 1; ++j)
a[i][j].resize(C + 2);
}
d = a;
for (int i = 1; i <= A; ++i)
for (int j = 1; j <= B; ++j)
for (int k = 1; k <= C; ++k)
scanf("%d", &a[i][j][k]);
for (int i = l = 1; i <= n; ++i)
scanf("%d%d%d%d%d%d%d", &q[i].l1, &q[i].r1, &q[i].l2, &q[i].r2, &q[i].l3, &q[i].r3, &q[i].h);
while (l <= r)
if (P(m = l + r >> 1))
r = m - 1;
else
l = m + 1;
printf("%d", l);
return 0;
}