```#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, a, p, q, x, y, xx, yy;
long long ans, c[1005][1005];
int main(){
scanf("%d", &n);
while(n--){
scanf("%d%d%d%d%d", &k, &p, &q, &m, &a);
if(k == 1) x = p, xx = p+m, y = q, yy = q+m;
else if(k == 2) x = p, xx = p+m, y = q-m, yy = q;
else if(k == 3) x = p-m, xx = p, y = q, yy = q+m;
else x = p-m, xx = p, y = q-m, yy = q;
for(i=x; i<=xx; i++){
for(j=y; j<=yy; j++){
if(abs(i-p)+abs(j-q) <= m){
c[i][j] += a;
}
}
}
}
for(i=1; i<=1000; i++){
for(j=1; j<=1000; j++){
if(c[i][j] > ans) ans = c[i][j];
}
}
printf("%lld\n", ans);
return 0;
}```

```#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, a, p, q, x, y, xx, yy;
long long ans, c[1005][1005];
int main(){
scanf("%d", &n);
while(n--){
scanf("%d%d%d%d%d", &k, &p, &q, &m, &a);
if(k == 1){
for(i=0; i<=m; i++){
c[p+i][q] += a, c[p+i][q+m+1-i] -= a;
}
}
if(k == 2){
for(i=0; i<=m; i++){
c[p+i][q-m+i] += a, c[p+i][q+1] -= a;
}
}
if(k == 3){
for(i=0; i<=m; i++){
c[p-i][q] += a, c[p-i][q+m+1-i] -= a;
}
}
if(k == 4){
for(i=0; i<=m; i++){
c[p-i][q-m+i] += a, c[p-i][q+1] -= a;
}
}
}
for(i=1; i<=1000; i++){
for(j=1; j<=1000; j++){
c[i][j] += c[i][j-1];
if(c[i][j] > ans) ans = c[i][j];
}
}
printf("%lld\n", ans);
return 0;
}```

33 34 35 36 37
43 44 45 46
53 54 55
63 64
73

```#include <bits/stdc++.h>
#define N 1005
using namespace std;
int n, m, i, j, k, a, p, q;
long long ans, c[N][N], x[N][N], y[N][N], s[N][N];
int main(){
scanf("%d", &n);
while(n--){
scanf("%d%d%d%d%d", &k, &p, &q, &m, &a);
//c记录列，x记录右往左的斜，y记录左往右的斜
if(k == 1){
c[p][q] += a, c[p+m+1][q] -= a;//左+1
x[p][q+m+1] -= a, x[p+m+1][q] += a;//斜-1
}
if(k == 2){
y[p][q-m] += a, y[p+m+1][q+1] -= a;//斜+1
c[p][q+1] -= a, c[p+m+1][q+1] += a;//右-1

}
if(k == 3){
c[p-m][q] += a, c[p+1][q] -= a;//左+1
y[p-m][q+1] -= a, y[p+1][q+m+1+1] += a;//斜-1
}
if(k == 4){
x[p-m][q] += a, x[p+1][q-m-1] -= a;//斜+1
c[p-m][q+1] -= a, c[p+1][q+1] += a;//右-1
}
}
for(i=1; i<=1000; i++){
for(j=k=1; j<=1000; j++){
c[i][j] += c[i-1][j];
x[i][j] += x[i-1][j+1];
y[i][j] += y[i-1][j-1];
s[i][j] = c[i][j] + x[i][j] + y[i][j];//差分标记复原
s[i][j] += s[i][j-1];//差分标记求前缀和
if(s[i][j] > ans) ans = s[i][j];
}
}
printf("%lld\n", ans);
return 0;
}```