public class Main {
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] arr = new int[n];
int k = 0;
for (int i = 0; i < arr.length; i++) {
k += scanner.nextInt();
arr[i] = k;
}
int q = scanner.nextInt();
for (int i = 0; i < q; i++) {
int a = scanner.nextInt();
int b = scanner.nextInt();
if (a == 1) {
System.out.println(arr[b - 1]);
} else {
System.out.println(arr[b - 1] - arr[a - 2]);
}
}
}
문제 http://59.23.150.58/30stair/rsq/rsq.php?pname=rsq
답
import java.util.Scanner;
public class Main { public static void main(String args[]) {
}