why WA1 ???? my program do right answer
I write Pascal a few day's. I not understand and nor find my error. Please help!
My code:
function M(a,b:integer):integer ;
begin
if a > b then result := a
else result := b
end;
procedure update(t: array of integer; v, tl, tr, pos, new_val: integer) ;
var
tm: integer;
begin
if tl = tr then t[v] := new_val
else
begin
tm := (tl+tr) div 2;
if pos <= tm then
update (t,v*2, tl, tm, pos, new_val)
else
update (t,v*2+1, tm+1, tr, pos, new_val);
t[v] := M(t[v*2], t[2*v+1]);
end;
end;
var
u, j, a, i, flag: integer;
f : string;
t : array of integer;
begin
readln(u);
SetLength(t,25001);
for j:=1 to 25000 do
t[j] := -1;
i := 1;
flag := 0;
WHILE true do
begin
readln(a);
if a = -1 then break;
update(t, 2, 1, u, i, a);
i := i + 1;
if i = u+1 then flag := 1 ;
if i = u+1 then i := 1 ;
if flag = 1 then
writeln(t[2]);
end;
end.
Re: why WA1 ???? my program do right answer
You missed "var" here:
procedure update(var t: array of integer; v, tl, tr, pos, new_val: integer) ;
Your local compiler is weird a bit if your program works as is. What is it?