AcWing 795. 前缀和
原题链接
简单
作者:
不知名的fE
,
2024-11-20 19:45:46
,
所有人可见
,
阅读 1
import java.util.*;
public class Main {
static final int N = 100010;
static int[] a = new int[N];
static int n, m;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt(); m = sc.nextInt();
sc.nextLine();
String[] s = sc.nextLine().split(" ");
for (int i = 1; i <= n; i++) {
a[i] = Integer.parseInt(s[i - 1]);
a[i] += a[i - 1];
}
while (m -- > 0) {
int l = sc.nextInt(), r = sc.nextInt();
System.out.println(a[r] - a[l - 1]);
}
}
}