当前位置:网站首页>[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"); } }
边栏推荐
- JDBC reads MySQL data list
- Common operation and Principle Exploration of stream
- 盲測調查顯示女碼農比男碼農更優秀
- How to add data to the back-end database in the form of Excel file on the web page
- 索引+sql练习优化
- Import and export database related tables from the win command line
- 【11. 二维差分】
- 基础知识 | js基础
- 碎煤机crusher
- JDBC transaction commit case
猜你喜欢
![[Kevin's third play in a row] is rust really slower than C? Further analyze queen micro assessment](/img/ac/44e0ecd04fbea5efd39d2cc75dea59.jpg)
[Kevin's third play in a row] is rust really slower than C? Further analyze queen micro assessment

【13. 二进制中1的个数、位运算】
![[Software Engineering] software engineering review outline of Shandong University](/img/38/2c783df56b50dee3bbb908f6f3e70e.png)
[Software Engineering] software engineering review outline of Shandong University

Online text digit recognition list summation tool

VNC Viewer方式的远程连接树莓派

js成绩奖惩例题

Common operation and Principle Exploration of stream

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

JS to determine whether the number entered by the user is a prime number (multiple methods)

win10-如何管理开机启动项?
随机推荐
期货反向跟单靠谱吗?
What is a flotation machine?
JS to determine whether the number entered by the user is a prime number (multiple methods)
JS use the switch statement to output the corresponding English day of the week according to 1-7
(resolved) the following raise notimplementederror occurs when Minet tests
Multi table associated query -- 07 -- hash join
Futures reverse Documentary - training for traders
The IPO of Yefeng pharmaceutical was terminated: Yu Feng, the actual controller who had planned to raise 540million yuan, made P2P investment
How to view program running time (timer) in JS
Blind survey shows that female code farmers are better than male code farmers
Set the address book function to database maintenance, and add user name and password
爬一个网页的所有导师信息
Mobile security tools -jad
How to add data to the back-end database in the form of Excel file on the web page
Cookie encryption 7 fidder analysis phase
洛谷刷题心得记录
野风药业IPO被终止:曾拟募资5.4亿 实控人俞蘠曾进行P2P投资
【11. 二维差分】
二叉树结构以及堆结构基础
SQL attendance query interval: one hour

