- package hahaha;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- public class ha {
- BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- String str,raw[];
- int n,m,sum[];
- ha() throws Exception
- {
- while((str=br.readLine())!=null)
- {
- raw=str.split(" ");
- n=Integer.parseInt(raw[0]);
- m=Integer.parseInt(raw[1]);
- sum=new int[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--;
- }
- }
- }
- int getSum(int l,int r)
- {
- return sum[r]-sum[l-1];
- }
- public static void main(String[] args) throws Exception {
- new ha();
- }
- }
複製代碼 |