| 记录编号 | 
        137847 | 
        评测结果 | 
        AAAAAAAAAA | 
    
    
        | 题目名称 | 
        36.求和问题 | 
        最终得分 | 
        100 | 
            
    
    
        | 用户昵称 | 
         helloworld123 | 
        是否通过 | 
        通过 | 
    
    
        | 代码语言 | 
        Pascal | 
        运行时间 | 
        0.924 s  | 
    
    
        | 提交时间 | 
        2014-11-05 12:00:20 | 
        内存使用 | 
        0.29 MiB  | 
        
    
    
    
    		显示代码纯文本
		
		program cogs36;
var
  n,m,r,x,y,t,l:int64;
  i,j:longint;
  a,b:array[1..10000] of int64;
function  lowbit(x:longint):int64;
begin
 exit(x and(-x));
end;
procedure modfiy(x,w:longint);
begin
 while x<=n do
  begin
   inc(b[x],w);
   inc(x,lowbit(x));
  end;
end;
function sum(x:longint):int64;
var
 tt:int64;
begin
 tt:=0;
 while x>0 do
  begin
   inc(tt,b[x]);
   dec(x,lowbit(x));
  end;
  exit(tt);
end;
 begin
  assign(input,'sum.in'); reset(input);
  assign(output,'sum.out'); rewrite(output);
   readln(n);
   fillchar(a,sizeof(a),0);
   fillchar(b,sizeof(b),0);
   for
   i:=1 to n do
   begin read(a[i]);
     modfiy(i,a[i]);
   end;
   readln;
   readln(m);
   for i:=1 to m do
    begin
     readln(l,r);
     writeln(sum(r)-sum(l-1));
    end;
  close(input); close(output);
 end.