BOJ 11659 : 구간 합 구하기 4

구간 합을 구하는데 있어 메모리를 좀 더 쓰면서, 계산 횟수가 덜 해질 수 있는 방법을 생각해보자. 계산을 실시하는 한 쌍의 계산 시도를 할 수록 계산 횟수는 후다닥 증가한다. 그럼 미리 해두면 되겠다. 그쵸

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])