当前位置:网站首页>[11. two dimensional difference]
[11. two dimensional difference]
2022-06-27 07:51:00 【Little silly bird_ coding】
Two dimensional difference
Ideas :
- It is the same as the idea of one-dimensional difference ,
Let's take a look at my one-dimensional difference- Assume that the two-dimensional difference group is
b[][], In order to(x1,y1)It's the upper left corner ,(x2,y2)Add a to all elements of the submatrix in the lower right cornerc.
The illustration
subject
Enter a nn That's ok mm The integer matrix of columns , Input again qq Operations , Each operation contains five integers x1,y1,x2,y2,c, among (x1,y1) and (x2,y2) Represents the upper left and lower right coordinates of a submatrix .
For each operation, add the value of each element in the selected sub matrix c.
Please output the matrix after all operations .
Input format
The first line contains integers n,m,q.
Next n That's ok , Each row contains m It's an integer , Represents an integer matrix .
Next q That's ok , Each row contains 5 It's an integer x1,y1,x2,y2,c, Represents an operation .
Output format
common n That's ok , Each row m It's an integer , Represents the final matrix after all operations are completed .
Data range
1 ≤ n,m ≤ 1000
1 ≤ q≤ 100000
1 ≤ x1 ≤ x2 ≤ n
1 ≤ y1 ≤ y2 ≤ m
−1000 ≤ c ≤ 1000
−1000 ≤ The values of the elements in the matrix ≤ 1000sample input :
3 4 3 1 2 2 1 3 2 2 1 1 1 1 1 1 1 2 2 1 1 3 2 3 2 3 1 3 4 1
Code
sample output :
2 3 4 1 4 3 4 1 2 2 2 2#include <iostream> using namespace std; const int N = 1010; int n, m, q; int a[N][N], b[N][N]; void insert(int x1, int y1, int x2, int y2, int c) { b[x1][y1] += c; b[x2 + 1][y1] -= c; b[x1][y2 + 1] -= c; b[x2 + 1][y2 + 1] += c; } int main() { scanf("%d%d%d", &n, &m, &q); for (int i = 1; i <= n; i ++) for (int j = 1; j <= m; j ++) scanf("%d", &a[i][j]); for (int i = 1; i <= n; i ++) for (int j = 1; j <= m; j ++) insert(i, j, i, j, a[i][j]); while (q --) { int x1, y1, x2, y2, c; cin >> x1 >> y1 >> x2 >> y2 >> c; insert(x1, y1, x2, y2, c); } for (int i = 1; i <= n; i ++) for (int j = 1; j <= m; j ++) b[i][j] += b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1]; for (int i = 1; i <= n; i ++) { for (int j = 1; j <= m; j ++) { printf("%d ", b[i][j]); } printf(" \n"); } }
边栏推荐
- How to bind SQL statements to web buttons
- 洛谷刷题心得记录
- 语音信号处理-概念(一):时谱图(横轴:时间;纵轴:幅值)、频谱图(横轴:频率;纵轴:幅值)--傅里叶变换-->时频谱图【横轴:时间;纵轴:频率;颜色深浅:幅值】
- How can I import data from Oracle into fastdfs?
- Publications under nature, science and cell
- js例题打印1-100之间所有7的倍数的个数及总和
- Futures reverse Documentary - training for traders
- win10-如何管理开机启动项?
- 参考 | Win11 开启热点之后电脑不能上网
- R language analyzing wine data
猜你喜欢

JS example print the number and sum of multiples of all 7 between 1-100

盲測調查顯示女碼農比男碼農更優秀

win10-如何管理开机启动项?

Programming life - what do you think of the 35 year old bottleneck of programmers?

Cookie encryption 7 fidder analysis phase
![[Software Engineering] software engineering review outline of Shandong University](/img/38/2c783df56b50dee3bbb908f6f3e70e.png)
[Software Engineering] software engineering review outline of Shandong University

Implementation of game hexagon map

PayPal账户遭大规模冻结!跨境卖家如何自救?

2022爱分析· IT运维厂商全景报告

参考 | Win11 开启热点之后电脑不能上网
随机推荐
1-4 decimal representation and conversion
L'introduction en bourse de Wild Wind Pharmaceutical a pris fin: Yu pinzeng, qui avait l'intention de lever 540 millions de RMB, a effectué un investissement P2P.
The IPO of Yefeng pharmaceutical was terminated: Yu Feng, the actual controller who had planned to raise 540million yuan, made P2P investment
Import and export database related tables from the win command line
Experience record of Luogu's topic brushing
JDBC操作Mysql示例
Is futures reverse documentary reliable?
Speech signal processing - concept (4): Fourier transform, short-time Fourier transform, wavelet transform
语音信号处理-概念(二):幅度谱(短时傅里叶变换谱/STFT spectrum)、梅尔谱(Mel spectrum)【语音的深度学习主要用幅度谱、梅尔谱】【用librosa或torchaudio提取】
js中判断奇偶的函数,求圆面积的函数
VNC Viewer方式的远程连接树莓派
How to view program running time (timer) in JS
Publications under nature, science and cell
Speech signal processing - concept (II): amplitude spectrum (STFT spectrum), Mel spectrum [the deep learning of speech mainly uses amplitude spectrum and Mel spectrum] [extracted with librosa or torch
[paper reading] internally semi supervised methods
JS performance reward and punishment examples
准备好迁移上云了?请收下这份迁移步骤清单
参考 | Win11 开启热点之后电脑不能上网
C how to call line and rows when updating the database
log4j:WARN No such property [zipPermission] in org. apache. log4j. RollingFileAppender.

