- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class a693 {
- int n,m,sum[],a,b;
- String raw[],str;
- BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- a693() throws IOException
- {
- 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;
- }
- for(int i=0;i<m;i++)
- {
- raw=br.readLine().split(" ");
- a=Integer.parseInt(raw[0]);
- b=Integer.parseInt(raw[1]);
- System.out.println(sum[b]-sum[a-1]);
- }
- }
- }
- public static void main(String[] args) throws IOException {
- new a693();
- }
- }
複製代碼 |