Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- N, M, K = list(map(int,input().split()))
- a = []
- for r in range(N):
- a.append(list(map(int,input().split())))
- s = 0
- ss = [[0 for c in range(M)] for r in range(N)]
- def sumrc(r2,c2):
- s = 0
- for r in range(r2+1):
- for c in range(c2+1):
- s += a[r][c]
- return s
- for r in range(N):
- for c in range(M):
- ss[r][c] = sumrc(r,c)
- rc = []
- for r in range(K):
- rc.append(list(map(int,input().split())))
- for y1,x1,y2,x2 in rc:
- x1 -= 1
- y1 -= 1
- x2 -= 1
- y2 -= 1
- print(ss[x2][y2] - ss[x1][y2-1] - ss[x2- 1][y1] + ss[x1- 1][y1 - 1])
Advertisement
Add Comment
Please, Sign In to add comment