当前位置:网站首页>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;
}
}
边栏推荐
- STM32GPIO口的工作原理
- Understanding of maximum likelihood estimation
- 2022 high altitude installation, maintenance and demolition examination materials and high altitude installation, maintenance and demolition operation certificate examination
- The persistence mode of redis - RDB and AOF persistence mechanisms
- Redis集群
- Deep learning website
- Talk about smart Park
- common commands
- 批次管控如何实现?MES系统给您答案
- About snake equation (2)
猜你喜欢
Talk about smart Park
The foreach map in JS cannot jump out of the loop problem and whether foreach will modify the original array
Redis 主从复制
Transportation, new infrastructure and smart highway
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
2022 new examination questions for crane driver (limited to bridge crane) and question bank for crane driver (limited to bridge crane) operation examination
Gnuradio transmits video and displays it in real time using VLC
城市土地利用分布数据/城市功能区划分布数据/城市poi感兴趣点/植被类型分布
2021-03-14 - play with generics
2021 Shanghai safety officer C certificate examination registration and analysis of Shanghai safety officer C certificate search
随机推荐
How does Matplotlib generate multiple pictures in turn & only save these pictures without displaying them in the compiler
4. Apprentissage stratégique
Gnuradio operation error: error thread [thread per block [12]: < block OFDM_ cyclic_ prefixer(8)>]: Buffer too small
从cmath文件看名字是怎样被添加到命名空间std中的
Leetcode exercise - Sword finger offer 36 Binary search tree and bidirectional linked list
正则表达式
common commands
NPM Internal Split module
快速熟知XML解析
2、TD+Learning
COMSOL----微阻梁模型的搭建---最终的温度分布和变形情况---材料的添加
About snake equation (1)
The usage of rand function in MATLAB
Gnuradio transmits video and displays it in real time using VLC
npm 內部拆分模塊
4、策略學習
从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
Mysql database (2)
2022 safety officer-a certificate free examination questions and safety officer-a certificate mock examination
break algorithm---刷题map