- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class SUSPECIOUS {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- SUSPECIOUS() throws Exception {
- int n, m, l, r;
- int sum[];
- String str,raw[];
- while ((str = br.readLine()) != null) {
- raw=str.split(" ");
- n = Integer.parseInt(raw[0]);
- m = Integer.parseInt(raw[1]);
- sum=new int[n+1];
- raw = br.readLine().split(" ");
- for (int i = 1; i <= n; i++){
- int t=Integer.parseInt(raw[i-1]);
- sum[i] = sum[i-1]+t;
- }
- /*
- for(int i:sum)
- System.out.print(i+" ");
- System.out.println();
- */
- for(int i=0;i<m;i++){
- raw=br.readLine().split(" ");
- l = Integer.parseInt(raw[0]);
- r = Integer.parseInt(raw[1]);
- System.out.println(sum[r]-sum[l-1]);
- }
- }
- }
- /*
- 3 3
- 1 2 3
- 1 3
- 1 2
- 2 3
- */
- public static void main(String[] args) throws Exception {
- new SUSPECIOUS();
- }
- }
複製代碼 |