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 1019. Line Painting

What is crash( access_violation )?
Posted by raxtinhac 11 Jun 2002 16:02
 I tried some tests but I didn't find the test make me get that
mistake or something like that.
  Here is my program, could you tell me why or give me the test make
me wrong or mistake.

const    max    = 5100;
         han    = 1000000000;

var      a           :array[1..2*max] of longint;
         cl          :array[1..2*max] of byte;
         line        :array[0..max] of record x,y :longint;
                                              c   :byte;
                                       end;

         m,k,n       :longint;
         dau,kq      :longint;

procedure them(u,v,t :longint);
begin
  inc(m);
  with line[m] do
  begin x := u;
        y := v;
        c := t;
  end;
  inc(k); a[k] := u;
  inc(k); a[k] := v;
end;


procedure chuanbi;
begin
  m := 0; k := 2;
  line[0].x := 0; line[0].y := han; line[0].c := 1;
  a[1] := 0; a[2] := han;
end;


procedure input;
var   i         :integer;
      u,v       :longint;
      t         :byte;
      st        :string;
begin
  chuanbi;

  readln( n);
  for i := 1 to n do
  begin
    readln( u, v, st);
    if pos('b',st) > 0 then t := 2
                       else t := 1;
    if u < v then
     them(u,v,t);
  end;
end;


procedure sort(l,r :longint);
var     i,j,tam,x    :longint;
begin
  i := l; j := r; x := a[ l + random(r-l+1)];

  repeat
    while a[i] < x do inc(i);
    while a[j] > x do dec(j);

    if i <= j then
    begin
      tam := a[i]; a[i] := a[j]; a[j] := tam;
      inc(i); dec(j);
    end;
  until i > j;

  if l < j then sort(l,j);
  if i < r then sort(i,r);
end;


procedure xoa(j,i :longint);
var    u  :longint;
begin
  k := k -i +j +1;
  for u := j+1 to k do
    a[u] := a[u+i-j-1];
end;


procedure rut_gon;
var      i,j      :longint;
begin
  i := k;
  repeat
    j := i;
    repeat dec(j) until a[j] < a[i];
    if j < i-1 then xoa(j,i);
    i := j;
  until i = 1;
end;


function tt( x : longint) :longint;
var     dau,cuoi,giua     :longint;
begin
  dau := 1; cuoi := k;

  repeat
    giua := ( dau + cuoi ) div 2;
    if x = a[giua] then begin tt := giua; exit; end;
    if x < a[giua] then cuoi := giua -1 else
                        dau  := giua +1;
  until false;
end;



procedure to_mau;
var   i,u,v,t      :longint;
begin
  for i := 0 to m do
    with line[i] do
    begin
      u := tt( x ); v := tt( y );
      for t := u to v-1 do
         cl[t] := c;
    end;
end;



procedure tim;
var   i,kq,dau,length,x   :longint;

 procedure update;
 begin
   if length > kq then
   begin  kq  := length;
          dau := x;
   end;
 end;

begin
  kq := 0;  dau := 0;
  length := 0; x := -1;

  for i := 1 to k-1 do
   if cl[i] = 1 then
   begin
     if x = -1 then x := a[i];
     length := length + a[i+1] - a[i];
   end else
   if length > 0 then
   begin
     update;
     length := 0; x := -1;
   end;

   update;
   writeln( dau,' ',dau + kq);
end;


procedure solve;
begin
  sort(1,k);
  rut_gon;
  to_mau;
  tim;
end;



begin
  input;
  solve;
end.
thank you. I've found it.
Posted by raxtinhac 11 Jun 2002 18:15
>  I tried some tests but I didn't find the test make me get that
> mistake or something like that.
>   Here is my program, could you tell me why or give me the test
make
> me wrong or mistake.
>
> const    max    = 5100;
>          han    = 1000000000;
>
> var      a           :array[1..2*max] of longint;
>          cl          :array[1..2*max] of byte;
>          line        :array[0..max] of record x,y :longint;
>                                               c   :byte;
>                                        end;
>
>          m,k,n       :longint;
>          dau,kq      :longint;
>
> procedure them(u,v,t :longint);
> begin
>   inc(m);
>   with line[m] do
>   begin x := u;
>         y := v;
>         c := t;
>   end;
>   inc(k); a[k] := u;
>   inc(k); a[k] := v;
> end;
>
>
> procedure chuanbi;
> begin
>   m := 0; k := 2;
>   line[0].x := 0; line[0].y := han; line[0].c := 1;
>   a[1] := 0; a[2] := han;
> end;
>
>
> procedure input;
> var   i         :integer;
>       u,v       :longint;
>       t         :byte;
>       st        :string;
> begin
>   chuanbi;
>
>   readln( n);
>   for i := 1 to n do
>   begin
>     readln( u, v, st);
>     if pos('b',st) > 0 then t := 2
>                        else t := 1;
>     if u < v then
>      them(u,v,t);
>   end;
> end;
>
>
> procedure sort(l,r :longint);
> var     i,j,tam,x    :longint;
> begin
>   i := l; j := r; x := a[ l + random(r-l+1)];
>
>   repeat
>     while a[i] < x do inc(i);
>     while a[j] > x do dec(j);
>
>     if i <= j then
>     begin
>       tam := a[i]; a[i] := a[j]; a[j] := tam;
>       inc(i); dec(j);
>     end;
>   until i > j;
>
>   if l < j then sort(l,j);
>   if i < r then sort(i,r);
> end;
>
>
> procedure xoa(j,i :longint);
> var    u  :longint;
> begin
>   k := k -i +j +1;
>   for u := j+1 to k do
>     a[u] := a[u+i-j-1];
> end;
>
>
> procedure rut_gon;
> var      i,j      :longint;
> begin
>   i := k;
>   repeat
>     j := i;
>     repeat dec(j) until a[j] < a[i];
>     if j < i-1 then xoa(j,i);
>     i := j;
>   until i = 1;
> end;
>
>
> function tt( x : longint) :longint;
> var     dau,cuoi,giua     :longint;
> begin
>   dau := 1; cuoi := k;
>
>   repeat
>     giua := ( dau + cuoi ) div 2;
>     if x = a[giua] then begin tt := giua; exit; end;
>     if x < a[giua] then cuoi := giua -1 else
>                         dau  := giua +1;
>   until false;
> end;
>
>
>
> procedure to_mau;
> var   i,u,v,t      :longint;
> begin
>   for i := 0 to m do
>     with line[i] do
>     begin
>       u := tt( x ); v := tt( y );
>       for t := u to v-1 do
>          cl[t] := c;
>     end;
> end;
>
>
>
> procedure tim;
> var   i,kq,dau,length,x   :longint;
>
>  procedure update;
>  begin
>    if length > kq then
>    begin  kq  := length;
>           dau := x;
>