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 compilation error? Please help me !
Posted by raxtinhac 14 Mar 2002 18:02
Here is my program :

const     max   = 15000;

var       a,pos,cs      :array[0..max] of word;

          n,m           :word;
          x             :longint;


procedure doi(u,v :word);
var    tam        :word;
begin
  tam := a[u]; a[u] := a[v]; a[v] := tam;
  pos[ cs[u] ] := v; pos[ cs[v] ] := u;
  tam := cs[u]; cs[u] := cs[v]; cs[v] := tam;
end;


procedure upheap(k :word);
var   v   :word;
begin
  v := a[k]; a[0] := maxint;
  while a[k div 2] <= v do
  begin
    doi( k, k div 2);
    k := k div 2;
  end;
end;


procedure downheap( k :word);
var   j  :integer;
begin
  while k <= m div 2 do
  begin
    j := 2*k;
    if j < m then if a[j] < a[j+1] then inc(j);
    if a[k] >= a[j] then exit ;
    doi(k, j);
    k := j;
  end;
end;


procedure ghi_max;
begin
  writeln( a[1] );
end;


procedure xoa;
var   k       :word;
begin
  inc(n); if n = m+1 then n := 1;
  k := pos[n];

  doi(k,m); dec(m);
  if k > m then exit;

  upheap(k);
  downheap(k);
end;


procedure them;
begin
  inc(m);
  a[m] := x;
  cs[m] := n;
  pos[n] := m;
  upheap(m);
end;


begin
  readln( m);

  for n := 1 to m do
  begin   read( a[n]);
          pos[n] := n; cs[n] := n;
          upheap(n);
  end;

  repeat
    ghi_max;
    xoa;

    read( x);
    if x = -1 then exit;
    them;
  until false;
end.
Re: Why compilation error? Please help me !
Posted by Bedny Yuri (bedny@rain.ifmo.ru) 20 Mar 2002 00:10
> Here is my program :
>
> const     max   = 15000;
>
> var       a,pos,cs      :array[0..max] of word;
>
>           n,m           :word;
>           x             :longint;
>
>
> procedure doi(u,v :word);
> var    tam        :word;
> begin
>   tam := a[u]; a[u] := a[v]; a[v] := tam;
>   pos[ cs[u] ] := v; pos[ cs[v] ] := u;
>   tam := cs[u]; cs[u] := cs[v]; cs[v] := tam;
> end;
>
>
> procedure upheap(k :word);
> var   v   :word;
> begin
>   v := a[k]; a[0] := maxint;
>   while a[k div 2] <= v do
>   begin
>     doi( k, k div 2);
>     k := k div 2;
>   end;
> end;
>
>
> procedure downheap( k :word);
> var   j  :integer;
> begin
>   while k <= m div 2 do
>   begin
>     j := 2*k;
>     if j < m then if a[j] < a[j+1] then inc(j);
>     if a[k] >= a[j] then exit ;
>     doi(k, j);
>     k := j;
>   end;
> end;
>
>
> procedure ghi_max;
> begin
>   writeln( a[1] );
> end;
>
>
> procedure xoa;
> var   k       :word;
> begin
>   inc(n); if n = m+1 then n := 1;
>   k := pos[n];
>
>   doi(k,m); dec(m);
>   if k > m then exit;
>
>   upheap(k);
>   downheap(k);
> end;
>
>
> procedure them;
> begin
>   inc(m);
>   a[m] := x;
>   cs[m] := n;
>   pos[n] := m;
>   upheap(m);
> end;
>
>
> begin
>   readln( m);
>
>   for n := 1 to m do
>   begin   read( a[n]);
>           pos[n] := n; cs[n] := n;
>           upheap(n);
>   end;
>
>   repeat
>     ghi_max;
>     xoa;
>
>     read( x);
>     if x = -1 then exit;
>     them;
>   until false;
> end.
>

Hello! First of all, I sorry for my bad English.
And now:
programs on Timus are compiled in Delphi.
type Integer range in Delphi is &#8211;2147483648..2147483647,
type Word range in Delphi is 0..65535,
hence arices error='constant expression violates subrange bounds',
when you write 'a[0] := maxint' in procedure 'upheap'.
If you write a[0]:=65535 I think that all will be ok! :)