返回列表 發帖
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;

  4. public class SUSPECIOUS {
  5.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

  6.         SUSPECIOUS() throws Exception {
  7.                 int n, m, l, r;
  8.                 int sum[];
  9.                 String str,raw[];
  10.                 while ((str = br.readLine()) != null) {
  11.                         raw=str.split(" ");
  12.                         n = Integer.parseInt(raw[0]);
  13.                         m = Integer.parseInt(raw[1]);
  14.                         sum=new int[n+1];
  15.                         raw = br.readLine().split(" ");
  16.                         for (int i = 1; i <= n; i++){
  17.                                 int t=Integer.parseInt(raw[i-1]);
  18.                                 sum[i] = sum[i-1]+t;
  19.                         }
  20.                         /*
  21.                         for(int i:sum)
  22.                                 System.out.print(i+" ");
  23.                         System.out.println();
  24.                         */
  25.                         for(int i=0;i<m;i++){
  26.                                 raw=br.readLine().split(" ");
  27.                                 l = Integer.parseInt(raw[0]);
  28.                                 r = Integer.parseInt(raw[1]);
  29.                                 System.out.println(sum[r]-sum[l-1]);
  30.                         }
  31.                 }
  32.         }
  33. /*
  34. 3 3
  35. 1 2 3
  36. 1 3
  37. 1 2
  38. 2 3
  39. */
  40.         public static void main(String[] args) throws Exception {
  41.                 new SUSPECIOUS();
  42.         }

  43. }
複製代碼
林祐霆

TOP

返回列表