#9796: TLE……


pk1219 (新世纪庞可)


var
  n,m,a,b,i,j:longint;
  s,sum:array[1..100000] of integer;
begin
  while not eof do begin
    readln(n,m);
    for i:=1 to n do
      read(s[i]);
    for i:=n downto 1 do begin
      for j:=1 to i do
        sum[i]:=sum[i]+s[j];
    end;
    for i:=1 to m do begin
      readln(a,b);
      writeln(sum[b]-sum[a-1]);
    end;
  end;
end.

没有死加呀……为什么还是TLE?

#9819: Re:TLE……


s798 (丁丁教主)


var
  n,m,a,b,i,j:longint;
  s,sum:array[1..100000] of integer;
begin
  while not eof do begin
    readln(n,m);
    for i:=1 to n do
      read(s[i]);
    for i:=n downto 1 do begin
      for j:=1 to i do
        sum[i]:=sum[i]+s[j];
    end;
    for i:=1 to m do begin
      readln(a,b);
      writeln(sum[b]-sum[a-1]);
    end;
  end;
end.

没有死加呀……为什么还是TLE?

 



嗨嗨~~ 可以參考看看我的答案^O^ 

 

使用語言 : c 

網址 : blogeric.me or http://140.138.144.77/?p=115 

#10908: Re:TLE……


uopsdod (samcom)


 

 

要先建表喔

比如有1 2 3 4 5 6 7 8 9 這幾種食物飽足值,

food[0]  = 1;

food[1] = 2 + food[0];

food[2] = food[1] + 3;

.... 

food[8] = food[7] + 9;

然後再根據要從哪開始吃和吃到哪

sum = food[end] - food[start-1];

 

 

先自己試試看吧,

如果有需要,

以下是我用C++寫得,給你參考:)

http://pastebin.com/HMAT5Lpv