Cod sursa(job #25460)

Utilizator andrei_blanaruAndrei Blanaru andrei_blanaru Data 4 martie 2007 12:39:36
Problema Ograzi Scor 20
Compilator fpc Status done
Runda preONI 2007, Runda 3, Clasele 11-12 Marime 1.27 kb
type punct=record
             x,y:integer;
           end;
var a:array [1..3000,1..3000] of word;
    o:array [1..50000] of punct;
    n,m,w,h,all:longint;

procedure update(x,y:integer);
var i,j:integer;
begin
  i:=x;
  while i<=3000 do
    begin
      j:=y;
      while j<=3000 do
        begin
          inc(a[i,j]);
          j:=j+(j xor (j-1))and j;
        end;
      i:=i+(i xor (i-1))and i;
    end;
end;


procedure citire;
var i,x,y:longint;
begin
  assign(input,'ograzi.in');
  reset(input);
  readln(n,m,w,h);
  for i:=1 to n do
      readln(o[i].x,o[i].y);
  for i:=1 to m do
    begin
      readln(x,y);
      update(x+1,y+1);
    end;
  close(input);
end;

function suma(x,y:integer):word;
var s,i,j:word;
begin
  s:=0;
  i:=x;
  while i>0 do
    begin
      j:=y;
      while j>0 do
        begin
          s:=s+a[i,j];
          j:=j-(j xor (j-1))and j;
        end;
      i:=i-(i xor (i-1))and i;
    end;
  suma:=s;
end;

procedure prel;
var i:longint;
begin
  for i:=1 to n do
    all:=all+suma(o[i].x+w+1,o[i].y+h+1)+suma(o[i].x,o[i].y)-suma(o[i].x+w+1,o[i].y)-suma(o[i].x,o[i].y+h+1);
end;


begin
  citire;
  prel;
  assign(output,'ograzi.out');
  rewrite(output);
  writeln(all);
  close(output);
end.