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

  4. public class a693 {
  5.         int n,m,sum[],a,b;
  6.         String raw[],str;
  7.         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  8.         a693() throws IOException
  9.         {
  10.                 while((str=br.readLine())!=null)
  11.                 {
  12.                         raw=str.split(" ");
  13.                         n=Integer.parseInt(raw[0]);
  14.                         m=Integer.parseInt(raw[1]);
  15.                         sum=new int[n+1];
  16.                         raw=br.readLine().split(" ");
  17.                         for(int i=1;i<=n;i++)
  18.                         {
  19.                                 int t=Integer.parseInt(raw[i-1]);
  20.                                 sum[i]=sum[i-1]+t;
  21.                         }
  22.                         for(int i=0;i<m;i++)
  23.                         {
  24.                                 raw=br.readLine().split(" ");
  25.                                 a=Integer.parseInt(raw[0]);
  26.                                 b=Integer.parseInt(raw[1]);
  27.                                 System.out.println(sum[b]-sum[a-1]);
  28.                         }
  29.                 }
  30.         }
  31.         public static void main(String[] args) throws IOException {
  32.                 new a693();
  33.         }
  34. }
複製代碼

TOP

返回列表