AcWing 796. 子矩阵的和
原题链接
简单
作者:
将情怀讲泛滥的恶果
,
2021-03-28 15:19:51
,
所有人可见
,
阅读 257
直接用一维前缀和会超时
if __name__=="__main__":
n,m,q = [int(x) for x in input().split()]
sums = [[0 for x in range(0,m+1)]]
for i in range(0,n):
temp_row = [0] + [int(x) for x in input().split()]
temp_sums=[0]
for j in range(1,m+1):
temp_sums.append(temp_row[j]+temp_sums[j-1])
sums.append(temp_sums)
for i in range(0,q):
left_row,left_col,right_row,right_col = [int(x) for x in input().split()]
res = 0
for i in range(left_row,right_row + 1):
res+=sums[i][right_col]-sums[i][left_col-1]
print(res)