题目大意
在类似 mc 的反重力世界中,有一个 大方块,每次敲掉其中的一个方块,同时询问有多少种方案能放下一个 的块。
题目分析
若是直接模拟,数组都开不下。
但是如果放在一个二维平面上考虑,问题会简单很多:
我们用 表示一个从 到 的方块
压缩 轴,用 表示 及其上方有多少奶酪块。
那么 到 能够贡献答案,当且仅当 。
同理地,压缩其他坐标轴,也有类似的结论。
于是只用开三个二维数组分别记录下就行。时间复杂度 ,空间复杂度 。
代码实现
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <ctime>
#include <random>
using namespace std;
const int INF = 0x3f3f3f3f;
inline int read()
{
int w = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
w = (w << 1) + (w << 3) + (ch ^ 48);
ch = getchar();
}
return w * f;
}
inline void write(int x)
{
if (x < 0)
{
putchar('-');
x = -x;
}
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
const int maxn=1005;
int n,q;
int res1[maxn][maxn],res2[maxn][maxn],res3[maxn][maxn];
//res1 固定x,y当前剩的z
//res2 固定x,z当前剩的y
//res3 固定y,z当前剩的x
int main()
{
n=read(),q=read();
for(int i=1;i<=n;++i)
{
for(int j=1;j<=n;++j)
{
res1[i][j]=res2[i][j]=res3[i][j]=n;
}
}
int ans=0;
for(int i=1,x,y,z;i<=q;++i)
{
x=read(),y=read(),z=read();
++x,++y,++z;
res1[x][y]--,res2[x][z]--,res3[y][z]--;
if(res1[x][y]==0) ++ans;
if(res2[x][z]==0) ++ans;
if(res3[y][z]==0) ++ans;
cout<<ans<<endl;
}
return 0;
}