7.区间和--前缀和
作者:
三行四列行列式
,
2024-11-19 23:15:14
,
所有人可见
,
阅读 2
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int []a = new int[1000100];
int []b = new int[1000100];
for(int i=0;i<n;i++) {
a[i] = sc.nextInt();
b[i] = a[i];
}
for(int i=1;i<n;i++) b[i]+=b[i-1];
while(sc.hasNextInt()){
int l=sc.nextInt(),r = sc.nextInt();
if(l==0) System.out.println(b[r]);
else{
int res = b[r]-b[l-1];
System.out.println(res);
}
}
}
}