-
-
Save zhrkvl/e95587768b08e69698d9d58c16f8e212 to your computer and use it in GitHub Desktop.
FOR 3axap!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import stdin, stdout, stderr | |
import math | |
def main(): | |
h, w, n = list(map(int, stdin.readline().split())) | |
field = [[0 for j in range(w)] for i in range(h)] | |
for i in range(h): | |
field[i] = list(map(int, stdin.readline().split())) | |
f = [[0 for j in range(w)] for i in range(h)] | |
f[0][0] = field[0][0] | |
for i in range(1, w): | |
f[0][i] = f[0][i - 1] + field[0][i] | |
for i in range(1, h): | |
f[i][0] = f[i - 1][0] + field[i][0] | |
print(type(f[1][1])) | |
for i in range(1, h): | |
for j in range(1, w): | |
f[i][j] = f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + field[i][j] | |
for i in range(n): | |
a, b, c, d = map(int, stdin.readline().split()) | |
c -= 1 | |
d -= 1 | |
a -= 1 | |
b -= 1 | |
todel = (0 if a == 0 else f[a - 1][d]) + (0 if b == 0 else f[c][b - 1]) | |
stdout.write(str(f[c, d] - todel + (0 if a == 0 and b == 0 else f[a - 1][b - 1]))) | |
if __name__ == '__main__': | |
main() | |
#(n-1)*(n-2) | |
#n**2-3*n+2 | |
#n*(n-3)+2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment