import java.util.*;
public class Main{
public static void main(String[] args){
int N = 100010;
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int[] arr = new int[N];
for(int i = 1; i <= n; i){
arr[i] = in.nextInt();
}
int[] s = new int[N];
s[0] = 0;
for(int i = 1; i <= n; i){
s[i] = s[i - 1] + arr[i];
}
while(m– > 0){
int l = in.nextInt();
int r = in.nextInt();
System.out.println(s[r] - s[l - 1]);
}
}
}
可能试一下加
## 以上格式即可正确显示代码块,更多markdown使用方法可在分享区搜索markdown