返回列表 發帖
  1. import java.io.BufferedReader;
  2. import java.io.InputStream;
  3. import java.io.InputStreamReader;
  4. import java.io.Reader;
  5. import java.util.Arrays;


  6. public class A251 {
  7.         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  8.         String str,raw[];
  9.         int n,m;
  10.         long sum[];
  11.         A251()throws Exception
  12.         {
  13.                
  14.                 while((str=br.readLine())!=null){
  15.                         raw=str.split(" ");
  16.             n=Integer.parseInt(raw[0]);
  17.             m=Integer.parseInt(raw[1]);
  18.             sum=new long[n+1];
  19.             raw=br.readLine().split(" ");
  20.             for(int i=1;i<=n;i++)
  21.             {
  22.                     int t=Integer.parseInt(raw[i-1]);
  23.                     sum[i]=sum[i-1]+t;
  24.             }
  25.             while(m>0)
  26.             {
  27.                    
  28.                     raw=br.readLine().split(" ");
  29.                     int l=Integer.parseInt(raw[0]);
  30.                     int r=Integer.parseInt(raw[1]);
  31.                     System.out.println(getSum(l , r));
  32.                     m--;
  33.             }
  34.                 }
  35.                
  36.         }
  37.         long getSum(int l,int r)
  38.         {
  39.                 return sum[r]-sum[l-1];
  40.         }
  41.         public static void main(String[] args) throws Exception {
  42.                 // TODO 自動產生的方法 Stub
  43.                 new A251();
  44.         }

  45. }
複製代碼

TOP

返回列表