当前位置:网站首页>Sum of submatrix
Sum of submatrix
2022-07-08 01:41:00 【Sanmumuqi】
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 .
understand :
The code description :
Code :
#include<iostream>
using namespace std;
const int N=1010;
int n,m,q;
int a[N][N],s[N][N];
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];
}
}
// check
int x1,y1,x2,y2;
for(int i=0;i<q;i++)
{
cin>>x1>>y1>>x2>>y2;
cout<<(s[x2][y2]-s[x2][y1-1]-s[x1-1][y2]+s[x1-1][y1-1])<<endl;
}
}
边栏推荐
- Guojingxin center "friendship and righteousness" - the meta universe based on friendship and friendship, and the parallel of "honguniverse"
- Gnuradio operation error: error thread [thread per block [12]: < block OFDM_ cyclic_ prefixer(8)>]: Buffer too small
- The examination contents of the third batch of Guangdong Provincial Safety Officer a certificate (main person in charge) in 2021 and the free examination questions of the third batch of Guangdong Prov
- Redis master-slave replication
- 图解网络:揭开TCP四次挥手背后的原理,结合男女朋友分手的例子,通俗易懂
- npm 内部拆分模块
- NPM Internal Split module
- Kaptcha generates verification code on Web page
- 2022 R1 fast opening pressure vessel operation test question bank and R1 fast opening pressure vessel operation free test questions
- Mysql database (2)
猜你喜欢
液压旋转接头的使用事项
Probability distribution
Leetcode exercise - Sword finger offer 36 Binary search tree and bidirectional linked list
Redis集群
4. Apprentissage stratégique
Js中forEach map无法跳出循环问题以及forEach会不会修改原数组
4. Strategic Learning
用户之声 | 冬去春来,静待花开 ——浅谈GBase 8a学习感悟
Gnuradio operation error: error thread [thread per block [12]: < block OFDM_ cyclic_ prefixer(8)>]: Buffer too small
The solution of frame dropping problem in gnuradio OFDM operation
随机推荐
Problems of font legend and time scale display of MATLAB drawing coordinate axis
Redis集群
Solve the error: NPM warn config global ` --global`, `--local` are deprecated Use `--location=global` instead.
powerbuilder 中使用线程的方法
COMSOL - Construction of micro resistance beam model - final temperature distribution and deformation - establishment of geometric model
common commands
Codeforces Round #649 (Div. 2)——A. XXXXX
Scalar / vector / matrix derivation method
Euler Lagrange equation
Grey correlation analysis link (portal) matlab
3、多智能体强化学习
How does Matplotlib generate multiple pictures in turn & only save these pictures without displaying them in the compiler
Redis 主从复制
COMSOL----微阻梁模型的搭建---最终的温度分布和变形情况----几何模型的建立
2022 chemical automation control instrument examination summary and chemical automation control instrument simulation examination questions
2022 operation certificate examination for main principals of hazardous chemical business units and main principals of hazardous chemical business units
Gnuradio3.9.4 create OOT module instances
Frequency probability and Bayesian probability
redis的持久化方式-RDB和AOF 两种持久化机制
从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值