#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int qz[N],hz[N];
int cnt[N],sum[N];
void update(int l,int r,int x,int *p)
{
p[l]+=x;
p[r+1]-=x;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m,q;
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=n*m;i++) qz[i]=hz[i]=0;
for(int i=1;i<=n+m-1;i++)
{
cnt[i]=min({n+m-i,n,m,i});
sum[i]=sum[i-1]+cnt[i];
}
for(int i=1;i<=q;i++)
{
int x,y,s;
scanf("%d%d%d",&x,&y,&s);
int h=x+m-y;
int id=sum[h-1]+min(x,y);
int l=sum[h-1]+1;
int r=sum[h];
l=max(l,id-s);
r=min(r,id+s);
update(l,r,1,qz);
update(id,id,-1,qz);
h=x+y-1;
id=sum[h-1]+min(x,m-y+1);
l=sum[h-1]+1;
r=sum[h];
l=max(l,id-s);
r=min(r,id+s);
update(l,r,1,hz);
}
for(int i=1;i<=n*m;i++) qz[i]+=qz[i-1],hz[i]+=hz[i-1];
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int ans=0;
int h=i+m-j;
int id=sum[h-1]+min(i,j);
ans+=qz[id];
h=i+j-1;
id=sum[h-1]+min(i,m-j+1);
ans+=hz[id];
printf("%d ",ans);
}
puts("");
}
}
}
差分加模拟
最新推荐文章于 2022-05-06 22:25:22 发布