Cod sursa(job #177869)

Utilizator chelaru_t_achelaru traian andrei chelaru_t_a Data 13 aprilie 2008 18:52:46
Problema Zoo Scor 30
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.18 kb
type zoo1=record
          x,y:longint;
          end;
  zoo2=record
       x1,y1,x2,y2:longint;
       end;
var a:array [1..16000] of zoo1;
  b:array [1.. 100000] of zoo2;
  f,t:text;
  i,n,m:integer;

 procedure citire;
  var i:integer;
  begin
   readln(f,n);
   for i:=1 to n do readln(f,a[i].x,a[i].y);
   readln(f,m);
   for i:=1 to m do readln(f,b[i].x1,b[i].y1,b[i].x2,b[i].y2);
  end;

 procedure qsort(l,r:integer);
  var i,j:integer;
    x,aux:zoo1;
  begin
   i:=l;
   j:=r;
   x:=a[(l+r) div 2];
   repeat
   while a[i].x<x.x do i:=i+1;
   while a[j].x>x.x do j:=j-1;
   if i<=j then
     begin
     aux:=a[i];
     a[i]:=a[j];
     a[i]:=aux;
     i:=i+1;
     j:=i-1;
     end;
   until i>j;
   if l<j then qsort(l,j);
   if r>i then qsort(i,r);
  end;

 procedure ani(p:integer);
  var i,nr:integer;
  begin
   nr:=0;
   for i:=1 to n do
     if (a[i].x>=b[p].x1) and (a[i].x<=b[p].x2) and (a[i].y>=b[p].y1) and (a[i].y<=b[p].y2) then nr:=nr+1;
   writeln(t,nr);
  end;

begin
  assign(f,'zoo.in');
  assign(t,'zoo.out');
  reset(f);
  rewrite(t);
  citire;
  qsort(1,n);
  for i:=1 to m do ani(i);
  close(f);
  close(t);
end.