https://www.acmicpc.net/problem/11660
# 2023.01.02
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
number = [list(map(int, input().split())) for _ in range(n)]
dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(0, n):
for j in range(0, n):
dp[i+1][j+1]+=(dp[i][j+1]+dp[i+1][j]-dp[i][j]+number[i][j])
for i in range(m):
x1, y1, x2, y2 = map(int, input().split())
print(dp[x2][y2]-dp[x1-1][y2]-dp[x2][y1-1]+dp[x1-1][y1-1])
'Problem Solving > BOJ' 카테고리의 다른 글
[Stack] 4949 균형잡힌 세상 (0) | 2023.01.03 |
---|---|
[Brute Force] 7568 덩치 (1) | 2023.01.03 |
[DP] 9465 스티커 (0) | 2023.01.02 |
[Recursive] 1991 트리순회 (0) | 2023.01.02 |
[DP] 1932 정수 삼각형 (0) | 2023.01.02 |