赫克托尔和妻子安德洛玛克告别
题意简述
- 在 行 列的水面网格中作 次投石,给定每次投石的位置、初始强度和衰减速度。
- 投石产生的涟漪呈四联通向外扩散,每一圈涟漪呈正负交替状
- 投石位置处的涟漪强度为初始强度,此后每圈涟漪强度的绝对值呈公差为衰减速度的相反数的非负项等差数列(即应为负的项均为 。)
- 水池为无穷大的网格,但由于赫克托尔设置了结界,所以超出边界的涟漪都会湮灭,因此你只需输出前 行 列的网格。
- 最后的场景为每次投石的效果叠加,即每次投石对水池的影响之和。
- 定义 为水池第 行第 列的涟漪强度。
- 求
思路简述
子任务
依题意模拟、暴力即可。
子任务
由于 ,考虑对 的奇偶性分类讨论,发现可以确定正负号。注意到不考虑正负号就是一道差分,两者结合起来即可。
子任务
无专门算法。
子任务
在子任务 的基础上,考虑对 的奇偶性分类讨论,可以得到正负性。假如涟漪在边界内完全归零,注意到二维差分后的非零位置呈斜线分布,因此对对角线和反对角线分别做一次差分即可。边界情况特判即可。
复杂度分析
时间复杂度分析
显然地,。
空间复杂度分析
显然地,。
代码实现
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,k,x,y,c,d,arr1[2][3005][3005],arr2[2][3005][3005],arr3[2][3005],arr4[2][3005];
ll read(){
ll x = 0;
int f = 1;
char ch = getchar();
while(!isdigit(ch)){
if(ch == '-')f = -1;
ch = getchar();
}
while(isdigit(ch)){
x = x * 10 +(ch - '0');
ch = getchar();
}
return x * f;
}
void __write(ll x){
if(x < 0){
putchar('-');
x *= -1;
}
if(x > 9)__write(x / 10);
putchar(x % 10 + '0');
return ;
}
void write(ll x,char ch){
__write(x);
putchar(ch);
return ;
}
int main(){
n = read(),m = read(),k = read();
for(ll i = 1;i <= k;i++){
x = read(),y = read(),c = read(),d = read();
if(y - c / d >= 1)arr1[(x + y) % 2][x][y - c / d] += (c % d);
else{
ll t = c / d - y;
if(x - t >= 1)arr3[(x + y) % 2][x - t] += (c % d);
else arr3[(x + y) % 2][1] += (c % d);
arr3[(x + y) % 2][x + 1] -= (c % d);
if(x - t - 1 >= 1)arr1[(x + y) % 2][x - t - 1][1] += (c % d);
}
if(y - c / d + 1 >= 1)arr1[(x + y) % 2][x][y - c / d + 1] += (d - c % d);
else{
ll t = c / d - y - 1;
if(x - t >= 1)arr3[(x + y) % 2][x - t] += (d - c % d);
else arr3[(x + y) % 2][1] += (d - c % d);
arr3[(x + y) % 2][x + 1] -= (d - c % d);
if(x - t - 1 >= 1)arr1[(x + y) % 2][x - t - 1][1] += (d - c % d);
}
if(x - c / d - 1 >= 1)arr1[(x + y) % 2][x - c / d - 1][y + 1] -= (c % d);
else{
ll t = x - c / d - 1;
if(y + t + 1 >= 1)arr4[(x + y) % 2][y + t + 1] += (c % d);
else arr4[(x + y) % 2][1] += (c % d);
arr4[(x + y) % 2][y + 1] -= (c % d);
}
if(x - c / d >= 1)arr1[(x + y) % 2][x - c / d][y + 1] -= (d - c % d);
else{
ll t = x - c / d;
if(y + t + 1 >= 1)arr4[(x + y) % 2][y + t + 1] += (d - c % d);
else arr4[(x + y) % 2][1] += (d - c % d);
arr4[(x + y) % 2][y + 1] -= (d - c % d);
}
if(x + c / d + 1 <= n)arr1[(x + y) % 2][x + c / d + 1][y + 1] += (c % d);
else{
ll t = x + c / d + 1 - n;
if(y + t + 1 <= m)arr1[(x + y) % 2][n][y + t + 1] += (c % d);
}
if(x + c / d <= n)arr1[(x + y) % 2][x + c / d][y + 1] += (d - c % d);
else{
ll t = x + c / d - n;
if(y + t + 1 <= m)arr1[(x + y) % 2][n][y + t + 1] += (d - c % d);
}
if(y + c / d + 2 <= m)arr1[(x + y) % 2][x][y + c / d + 2] -= (c % d);
if(y + c / d + 1 <= m)arr1[(x + y) % 2][x][y + c / d + 1] -= (d - c % d);
if(y - c / d >= 1)arr2[(x + y) % 2][x + 1][y - c / d] -= (c % d);
else{
ll t = y - c / d;
arr3[(x + y) % 2][x + 1] -= (c % d);
if(x - t + 2 <= n)arr3[(x + y) % 2][x - t + 2] += (c % d);
if(x - t + 2 <= n)arr2[(x + y) % 2][x - t + 2][1] -= (c % d);
}
if(y - c / d + 1 >= 1)arr2[(x + y) % 2][x + 1][y - c / d + 1] -= (d - c % d);
else{
ll t = y - c / d + 1;
arr3[(x + y) % 2][x + 1] -= (d - c % d);
if(x - t + 2 <= n)arr3[(x + y) % 2][x - t + 2] += (d - c % d);
if(x - t + 2 <= n)arr2[(x + y) % 2][x - t + 2][1] -= (d - c % d);
}
if(x - c / d >= 1)arr2[(x + y) % 2][x - c / d][y + 1] -= (c % d);
else{
ll t = x - c / d;
arr4[(x + y) % 2][y + 1] -= (c % d);
if(y - t + 2 <= m)arr4[(x + y) % 2][y - t + 2] += (c % d);
if(y - t + 2 <= m)arr2[(x + y) % 2][1][y - t + 2] -= (c % d);
}
if(x - c / d + 1 >= 1)arr2[(x + y) % 2][x - c / d + 1][y + 1] -= (d - c % d);
else{
ll t = x - c / d + 1;
arr4[(x + y) % 2][y + 1] -= (d - c % d);
if(y - t + 2 <= m)arr4[(x + y) % 2][y - t + 2] += (d - c % d);
if(y - t + 2 <= m)arr2[(x + y) % 2][1][y - t + 2] -= (d - c % d);
}
if(y + c / d + 2 <= m)arr2[(x + y) % 2][x + 1][y + c / d + 2] += (c % d);
if(y + c / d + 1 <= m)arr2[(x + y) % 2][x + 1][y + c / d + 1] += (d - c % d);
if(x + c / d + 2 <= n)arr2[(x + y) % 2][x + c / d + 2][y + 1] += (c % d);
if(x + c / d + 1 <= n)arr2[(x + y) % 2][x + c / d + 1][y + 1] += (d - c % d);
if(x + y <= c / d)arr3[(x + y) % 2][1] += (c - (x + y) * d),arr3[(x + y) % 2][2] -= (c - (x + y) * d);
}
for(ll i = 0;i <= 1;i++){
for(ll k = 1;k <= m;k++)for(ll j = 1;j <= n;j++)arr1[i][j][k] += arr1[i][j + 1][k - 1],arr2[i][j][k] += arr2[i][j - 1][k - 1];
for(ll j = 1;j <= n;j++)arr3[i][j] += arr3[i][j - 1];
for(ll j = 1;j <= m;j++)arr4[i][j] += arr4[i][j - 1];
for(ll j = 1;j <= n;j++)for(ll k = 1;k <= m;k++)arr1[i][j][k] += arr2[i][j][k];
for(ll j = 1;j <= n;j++)arr1[i][j][1] += arr3[i][j];
for(ll j = 1;j <= m;j++)arr1[i][1][j] += arr4[i][j];
for(ll j = 1;j <= n;j++)for(ll k = 1;k <= m;k++)arr1[i][j][k] += arr1[i][j - 1][k];
for(ll j = 1;j <= n;j++)for(ll k = 1;k <= m;k++)arr1[i][j][k] += arr1[i][j][k - 1];
}
for(ll i = 1;i <= n;i++){
ll res = 0,s = 1;
for(ll j = 1;j <= m;j++){
s = s * 233 % 998244353;
ll now = ((arr1[1][i][j] - arr1[0][i][j]) % 998244353 + 998244353) % 998244353;
if((i + j) % 2 == 1)res = (res + now * s) % 998244353;
else res = (res - now * s % 998244353 + 998244353) % 998244353;
}
write(res,' ');
}
return 0;
}