16| 二位前缀和

代码实现

cpp 复制代码
typedef long long LL;
const int N = 1e3 + 10;
LL x, st[N][N], n, m, q;

int main()
{
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			cin >> x;
			st[i][j] = st[i-1][j] + st[i][j-1] - st[i-1][j-1] + x;
		}
	}
	while (q--)
	{
		int x1, x2, y1, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		cout << st[x2][y2] + st[x1-1][y1-1] - st[x1-1][y2] - st[x2][y1-1]<< endl; 
	}
	return 0;
 } 
相关推荐
寻寻觅觅☆13 小时前
东华OJ-基础题-106-大整数相加(C++)
开发语言·c++·算法
时代的凡人13 小时前
0208晨间笔记
笔记
fpcc13 小时前
并行编程实战——CUDA编程的Parallel Task类型
c++·cuda
偷吃的耗子14 小时前
【CNN算法理解】:三、AlexNet 训练模块(附代码)
深度学习·算法·cnn
今天只学一颗糖14 小时前
1、《深入理解计算机系统》--计算机系统介绍
linux·笔记·学习·系统架构
testpassportcn14 小时前
AWS DOP-C02 認證完整解析|AWS DevOps Engineer Professional 考試
网络·学习·改行学it
化学在逃硬闯CS14 小时前
Leetcode1382. 将二叉搜索树变平衡
数据结构·算法
ceclar12315 小时前
C++使用format
开发语言·c++·算法
Gofarlic_OMS15 小时前
科学计算领域MATLAB许可证管理工具对比推荐
运维·开发语言·算法·matlab·自动化
lanhuazui1015 小时前
C++ 中什么时候用::(作用域解析运算符)
c++