구간 합을 구하는데 있어 메모리를 좀 더 쓰면서, 계산 횟수가 덜 해질 수 있는 방법을 생각해보자. 계산을 실시하는 한 쌍의 계산 시도를 할 수록 계산 횟수는 후다닥 증가한다. 그럼 미리 해두면 되겠다. 그쵸
https://www.acmicpc.net/problem/11659
import sys
from collections import deque
input = sys.stdin.readline
numList = [0] * 100001
totalList = [0] * 100001
numCount, testCaseCount = list(map(int, input().split()))
numList = list(map(int, input().split()))
for i in range(0, numCount):
totalList[i] = totalList[i - 1] + numList[i]
for i in range(testCaseCount):
start, dest = list(map(int, input().split()))
if(start == 1):
print(totalList[dest - 1])
continue
if(start == dest):
print(numList[dest - 1])
continue
print(totalList[dest - 1] - totalList[start - 2])
'문제풀이' 카테고리의 다른 글
팰린드롬을 효율적으로 찾는 매내처 알고리즘 (0) | 2025.05.22 |
---|---|
BOJ 21736 : 헌내기는 친구가 필요해 (0) | 2025.05.21 |
BOJ 11727 : 2xn 타일링 2 (0) | 2025.05.17 |
BOJ 11726 : 2xn 타일링 (0) | 2025.05.17 |
BOJ 1475 : 방 번호 (0) | 2025.05.15 |