Created
June 14, 2022 05:59
-
-
Save mym0404/64f6690d3f916e563cbdf5221ffece6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 파이썬 빠른 입력 사용 | |
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