【模板】二维前缀和

 

题目:P1060 - 【模板】二维前缀和 - ETOJ (eriktse.com)

 

 

 

 

#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
const int N=1e3+23;
using ll=long long;
ll a[N][N],fix[N][N],diff[N][N];
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

ll n,m,q;cin>>n>>m>>q;

for(int i=1;i<=n;i++){

for(int j=1;j<=m;j++){
cin>>a[i][j];}}

for(int i=1;i<=n;i++){

for(int j=1;j<=m;j++){
fix[i][j]=a[i][j]+fix[i-1][j]+fix[i][j-1]-fix[i-1][j-1];}}

while(q--) {
	ll x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;
	
	cout<<fix[x2][y2]+fix[x1-1][y1-1]-fix[x2][y1-1]-fix[x1-1][y2]<<'\n';
}

}

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-03 23:54:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-03 23:54:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-02-03 23:54:01       82 阅读
  4. Python语言-面向对象

    2024-02-03 23:54:01       91 阅读

热门阅读

  1. C# 浅克隆与深克隆

    2024-02-03 23:54:01       50 阅读
  2. 微信小程序如何取得用户的openid

    2024-02-03 23:54:01       50 阅读
  3. 一周速递|全球车联网产业动态(2024年2月4日)

    2024-02-03 23:54:01       53 阅读
  4. golang sudog是什么?

    2024-02-03 23:54:01       49 阅读
  5. 智慧机场物联网应用及网络安全挑战(下)

    2024-02-03 23:54:01       51 阅读
  6. 前端项目接口请求封装

    2024-02-03 23:54:01       45 阅读
  7. 【校门外的树(洛谷 P1047)】

    2024-02-03 23:54:01       46 阅读
  8. ChatGPT炸裂了

    2024-02-03 23:54:01       48 阅读
  9. kubenetes使用ConfigMap挂载ssh公钥实现pod免密

    2024-02-03 23:54:01       44 阅读
  10. 机器学习复习(8)——基本概念

    2024-02-03 23:54:01       44 阅读
  11. 力扣(leetcode)第268题丢失的数字(Python)

    2024-02-03 23:54:01       54 阅读