boris-vlasenko

Untitled

Oct 20th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. N, M, K = list(map(int,input().split()))
  2. a = []
  3. for r in range(N):
  4.     a.append(list(map(int,input().split())))
  5.  
  6. s = 0
  7. ss = [[0 for c in range(M)] for r in range(N)]
  8.  
  9. def sumrc(r2,c2):
  10.     s = 0
  11.     for r in range(r2+1):
  12.         for c in range(c2+1):
  13.             s += a[r][c]
  14.     return s
  15.  
  16.  
  17. for r in range(N):
  18.     for c in range(M):
  19.         ss[r][c] = sumrc(r,c)
  20.        
  21.  
  22. rc = []
  23. for r in range(K):
  24.     rc.append(list(map(int,input().split())))
  25.  
  26. for y1,x1,y2,x2 in rc:
  27.     x1 -= 1
  28.     y1 -= 1
  29.     x2 -= 1
  30.     y2 -= 1
  31.     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