返回列表 發帖
  1. package hahaha;

  2. import java.io.BufferedReader;
  3. import java.io.InputStreamReader;

  4. public class ha {
  5.         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  6.         String str,raw[];
  7.         int n,m,sum[];
  8.         ha() throws Exception
  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.                         while(m>0)
  23.                         {
  24.                                 raw=br.readLine().split(" ");
  25.                                 int l=Integer.parseInt(raw[0]);
  26.                                 int r=Integer.parseInt(raw[1]);
  27.                                 System.out.println(getSum(l,r));
  28.                                 m--;
  29.                         }
  30.                 }
  31.         }
  32.         int getSum(int l,int r)
  33.         {
  34.                 return sum[r]-sum[l-1];
  35.         }
  36.         public static void main(String[] args) throws Exception {               
  37.                 new ha();
  38.         }
  39. }
複製代碼

TOP

返回列表