Skip to content

Instantly share code, notes, and snippets.

@modos
Created April 26, 2023 05:11
Show Gist options
  • Save modos/02b34eecda2e7326c2822ce595237a2d to your computer and use it in GitHub Desktop.
Save modos/02b34eecda2e7326c2822ce595237a2d to your computer and use it in GitHub Desktop.
مجموع جزئی در ماتریس
n, q = list(map(int, input().split(" ")))
ps = [[0] * (n + 1) for i in range(n + 1)]
A = []
for i in range(n):
B = list(map(int, input().split(" ")))
for j in range(n):
ps[i + 1][j + 1] = B[j] + ps[i][j + 1] + ps[i + 1][j] - ps[i][j]
for i in range(q):
l1, r1, l2, r2 = list(map(int, input().split(" ")))
l2 += 1
r2 += 1
print(ps[l2][r2] - ps[l2][r1] - ps[l1][r2] + ps[l1][r1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment