- import java.io.BufferedReader;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.Reader;
- import java.util.Arrays;
- public class A251 {
- BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- String str,raw[];
- int n,m;
- long sum[];
- A251()throws Exception
- {
-
- while((str=br.readLine())!=null){
- raw=str.split(" ");
- n=Integer.parseInt(raw[0]);
- m=Integer.parseInt(raw[1]);
- sum=new long[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;
- }
- while(m>0)
- {
-
- raw=br.readLine().split(" ");
- int l=Integer.parseInt(raw[0]);
- int r=Integer.parseInt(raw[1]);
- System.out.println(getSum(l , r));
- m--;
- }
- }
-
- }
- long getSum(int l,int r)
- {
- return sum[r]-sum[l-1];
- }
- public static void main(String[] args) throws Exception {
- // TODO 自動產生的方法 Stub
- new A251();
- }
- }
複製代碼 |