- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Ch01 {
- BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- String str[];
- int n,m,data[],res[];
- Ch01() throws Exception
- {
- while((str=br.readLine().split(" "))!=null)
- {
- n=Integer.parseInt(str[0]);
- m=Integer.parseInt(str[1]);
- data=new int[n+1];
- res=new int[n+1];
- str=br.readLine().split(" ");
- for(int i=1; i<=n; i++)
- {
- int t=Integer.parseInt(str[i-1]);
- res[i]=res[i-1]+t;
- }
- for(int i=0; i<m; i++)
- {
- str=br.readLine().split(" ");
- System.out.println(res[Integer.parseInt(str[1])]-(res[Integer.parseInt(str[0])-1]));
- }
-
- }
- }
- public static void main(String[] args) throws Exception {
- new Ch01();
- }
- }
複製代碼 |