Skip to content

Instantly share code, notes, and snippets.

@mym0404
Created June 14, 2022 05:59
Show Gist options
  • Save mym0404/64f6690d3f916e563cbdf5221ffece6c to your computer and use it in GitHub Desktop.
Save mym0404/64f6690d3f916e563cbdf5221ffece6c to your computer and use it in GitHub Desktop.
# 파이썬 빠른 입력 사용
import sys
input = sys.stdin.readline
# 입력 받기
n, m = map(int, input().split())
a = list(map(int, input().split()))
# 구간합 배열 만들기, 길이는 n + 1 개로 만들어주면 된다(원래 배열의 길이 + 1).
psum = [0 for _ in range(n + 1)]
for i in range(n):
psum[i + 1] = psum[i] + a[i]
for i in range(m):
l, r = map(int, input().split())
# 0-based 인덱스로 처리해주기 위해
l -= 1
r -= 1
print(psum[r + 1] - psum[l])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment