https://www.acmicpc.net/problem/15724
import sys
input = sys.stdin.readline
# 그래프
n, m = map(int, input().split())
graph = []
graph.append([0 for _ in range(m+1)])
for _ in range(n):
temp = list(map(int, input().split()))
graph.append([0] + temp)
sum = [[0 for _ in range(m+1)] for _ in range(n+1)]
for i in range(1, n+1):
for j in range(1, m+1):
sum[i][j] = graph[i][j] + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1]
tc = int(input())
for _ in range(tc):
x1, y1, x2, y2 = map(int, input().split())
total = 0
if x1 ==1 and y1==1:
total = sum[x2][y2]
else:
total = sum[x2][y2] - sum[x2][y1-1] - sum[x1-1][y2] + sum[x1-1][y1-1]
print(total)
728x90
반응형
'🔻PS > Baekjoon' 카테고리의 다른 글
[Baekjoon] 백준 26169 세 번 이내에 사과를 먹자 Python (0) | 2024.09.13 |
---|---|
[Baekjoon] 백준 1941 소문난 칠공주 Python (0) | 2024.07.29 |
[Baekjoon] 백준 2644 로또 (0) | 2024.07.10 |
[Baekjoon] 백준 2644 촌수계산 Python (0) | 2024.05.19 |
[Baekjoon] 백준 10026 적록색약 Python (0) | 2024.05.17 |