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 1126. Magnetic Storms

why WA1 ???? my program do right answer
Posted by Lev_Kireenko 🐬 4 Jan 2017 01:41
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
Posted by ToadMonster 4 Jan 2017 14:13
Please show your program answer on task example.
Re: why WA1 ???? my program do right answer
Posted by Lev_Kireenko 🐬 5 Jan 2017 02:40
11
11
10
0
1
2
3
3
Re: why WA1 ???? my program do right answer
Posted by ToadMonster 5 Jan 2017 19:40
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?
Re: why WA1 ???? my program do right answer
Posted by Lev_Kireenko 🐬 6 Jan 2017 21:28
Thanks! I got AC.

I used Pascal ABC.