题解 | #【模板】静态区间和(前缀和)#Python3
【模板】静态区间和(前缀和)
https://www.nowcoder.com/practice/ac79a1a4a66646cc87525d6faa86e021
n, q = map(int, input().split()) # 错开a[0]这个位置 a = [0] a.extend(list(map(int, input().split()))) b = a.copy() # 构造前缀和数列 for i in range(1, n+1): b[i] = b[i-1] + a[i] for _ in range(0, q): l, r = map(int, input().split()) print(b[r]-b[l-1])#15天刷题#