跳到正文

个人记录

赫克托尔和妻子安德洛玛克告别

xixihaha2021约 11 分钟
原文
文章信息与版本

文章信息

发布
2024年7月9日
收录
2026年10月27日
更新
2026年10月27日
篇幅
约 11 分钟

版本

  1. v1当前

赫克托尔和妻子安德洛玛克告别

题意简述

  • 在 nn 行 mm 列的水面网格中作 kk 次投石,给定每次投石的位置、初始强度和衰减速度。
  • 投石产生的涟漪呈四联通向外扩散,每一圈涟漪呈正负交替状
  • 投石位置处的涟漪强度为初始强度,此后每圈涟漪强度的绝对值呈公差为衰减速度的相反数的非负项等差数列(即应为负的项均为 00。)
  • 水池为无穷大的网格,但由于赫克托尔设置了结界,所以超出边界的涟漪都会湮灭,因此你只需输出前 nn 行 mm 列的网格。
  • 最后的场景为每次投石的效果叠加,即每次投石对水池的影响之和。
  • 定义 hi,jh_{i,j} 为水池第 ii 行第 jj 列的涟漪强度。
  • 求 ai=(∑j=1m233j⋅hi,j) mod 998244353.a_i=(\sum_{j=1}^{m} 233^j \cdot h_{i,j}) \bmod 998244353.

思路简述

子任务 11

依题意模拟、暴力即可。

子任务 22

由于 n=1n=1,考虑对 yiy_i 的奇偶性分类讨论,发现可以确定正负号。注意到不考虑正负号就是一道差分,两者结合起来即可。

子任务 33

无专门算法。防止有人正解打挂或者懒得写正解的。\color{white}{\text{防止有人正解打挂或者懒得写正解的。}}

子任务 44

在子任务 22 的基础上,考虑对 xi+yix_i+y_i 的奇偶性分类讨论,可以得到正负性。假如涟漪在边界内完全归零,注意到二维差分后的非零位置呈斜线分布,因此对对角线和反对角线分别做一次差分即可。边界情况特判即可。

复杂度分析

时间复杂度分析

显然地,O(NM)O(NM)。

空间复杂度分析

显然地,O(NM)O(NM)。

代码实现

C++
#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;
}
原文