当前位置:网站首页>Sum of acwing796 submatrix
Sum of acwing796 submatrix
2022-06-12 16:17:00 【_ Liuxiaoyu】
Enter a n That's ok m The integer matrix of columns , Input again q A asked , Each query contains four integers x1,y1,x2,y2, Represents the upper left and lower right coordinates of a submatrix .
For each query, the sum of all numbers in the output submatrix .
Input format
The first line contains three 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 line contains four integers x1,y1,x2,y2, A group of questions .
Output format
common q That's ok , Output one query result per line .
Data range
1≤n,m≤1000,
1≤q≤200000,
1≤x1≤x2≤n,
1≤y1≤y2≤m,
−1000≤ The values of the elements in the matrix ≤1000
Solution of two-dimensional difference : Subtract the area of two matrices , Then add the area of the repeated subtraction
S(i,j) How to calculate : S(i ,j) = S(i-1, j) + S(i, j - 1) - S(i-1, j -1) + a(i , j)
#include <iostream>
using namespace std;
const int N = 1010;
int a[N][N], s[N][N];
int n,m,q;
int main()
{
cin >> n >> m >> q;
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
{
cin >> a[i][j];
s[i][j] = s[i-1][j] + s[i][j-1]-s[i-1][j-1] + a[i][j]; // The prefix and
}
while(q--)
{
int x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
int re = s[x2][y2]-s[x1-1][y2] - s[x2][y1-1] + s[x1-1][y1-1]; // Submatrix and
cout << re <<endl;
}
return 0;
}
边栏推荐
- Explore the Apache shardingsphere SQL parse format function
- acwing796 子矩阵的和
- Read MHD and raw images, slice, normalize and save them
- Introduction and download website of common data of GIS, remote sensing, hydrology and Geography (2), supplementary~
- Decision tree classification and examples
- redis String类型常见命令
- C packing and unpacking
- Analysis on the development status and direction of China's cultural tourism real estate industry in 2021: the average transaction price has increased, and cultural tourism projects continue to innova
- The market share of packaged drinking water has been the first for eight consecutive years. How does this brand DTC continue to grow?
- 看《梦华录》上头的人都该尝试下这款抖音特效
猜你喜欢
大规模实时分位数计算——Quantile Sketches 简史
In 2020, the demand for strain sensors in China will reach 9.006 million, and the market scale will reach 2.292 billion yuan [figure]
What is JUC in high concurrency programming
Analysis on the development status and direction of China's cultural tourism real estate industry in 2021: the average transaction price has increased, and cultural tourism projects continue to innova
acwing796 子矩阵的和
The market share of packaged drinking water has been the first for eight consecutive years. How does this brand DTC continue to grow?
acwing 790. 数的三次方根(浮点数二分)
< 山东大学软件学院项目实训 > 渲染引擎系统——基础渲染器(六)
IDEA中文棱形乱码错误解决方法--控制台中文输出棱形乱码
联通网管协议框图
随机推荐
C regular expression
Global and Chinese markets for air sampling calibration pumps 2022-2028: Research Report on technology, participants, trends, market size and share
< 山东大学软件学院项目实训 > 渲染引擎系统——基础渲染器(六)
面试:‘==‘与equals()之间的区别
Project training of Software College of Shandong University rendering engine system radiation pre calculation (IX)
Web UI automation test
Redis string type common commands
acwing788. 逆序对的数量
puppeteer入门之 BrowserContext 类
[thinking about the process of structure optimization] how to build the evaluation ability of the impact of technical solutions
Step by step steps to create an ABAP program with a custom screen
Thinking about the probability of drawing cards in the duel link of game king
[OWT server] customized script 3: server construction
Project training of Software College of Shandong University rendering engine system basic renderer (V)
Axure RP 9 for MAC (interactive product prototyping tool) Chinese version
面试:hashCode()和equals()
Read MHD and raw images, slice, normalize and save them
Step by step to create a trial version of ABAP program containing custom screen
In 2020, the demand for strain sensors in China will reach 9.006 million, and the market scale will reach 2.292 billion yuan [figure]
思考游戏王决斗链接中抽卡概率问题