ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1330. Intervals

TimeLimit. Why.
Posted by AndreyIvanov19SSAu 28 Dec 2005 14:04
type vector=array[1..10000]of integer;
var a:vector;
function Summa(i,j:integer):longint;
var k:longint;
S:longint;
begin
S:=0;
   for k:=i to j do   S:=S+a[k];
Summa:=S;
end;
var i,j,k:integer;
    n:integer;
    q:longint;
begin
    read(n);
    for i:=1 to n do read(a[i]);
    read(q);
    for k:=1 to q do begin
        read(i,j);
if i=j then writeln(Summa(i,j)) else
    writeln(Summa(1,j)-Summa(1,i-1));
    end;
end.



Why TimeLimite. It's easy.
Re: TimeLimit. Why.
Posted by Burunduk1 29 Dec 2005 01:12
Your solution is O(N*Q).
N=10^4, Q=10^5 => N*Q = 10^9
So it works about one minute on max-test.