Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:ac的注意一下啊,下面两组数据不一定过~~~汗

Posted by vcvycy at 2013-04-22 11:44:02 on Problem 1177
In Reply To:ac的注意一下啊,下面两组数据不一定过~~~汗 Posted by:ACM_Qun at 2011-04-09 18:03:48
> 3
> 0 0 1 2
> 0 2 1 4
> 1 1 2 3
> 12
> 3
> 0 1 2 2
> 2 1 4 2
> 1 0 3 1
> 12
这两组都过了,可是WA~能不能指点下- -
const mm=1000000;
type
  cc=record
    l,r,k,p:longint;
    end;
type
  arr=array[0..50009]of cc;
type
  c1=record
    l,r,m,ld,rd,c,line:Longint;
    end;
var
  tr:array[0..151234]of c1;
  x,y,b:arr;
  i,j,k,m,n,x1,x2,y1,y2,ans,minx,miny,maxx,maxy,l,r,tt,lx,ly:Longint;
procedure init;
  begin
    read(n);
    minx:=mm;
    miny:=mm;
    maxx:=-mm;
    maxy:=-mm;
    for i:=1 to n do
      begin
        read(x1,y1,x2,y2);
        if x1<minx then minx:=x1;
        if x2>maxx then maxx:=x2;
        if y1<miny then miny:=y1;
        if y2>maxy then maxy:=y2;
        inc(lx);
        with x[lx] do begin l:=y1;r:=y2;k:=x1;end;
        inc(lx);
        with x[lx] do begin l:=y1;r:=y2;k:=x2;p:=1;end;
        inc(ly);
        with y[ly] do begin l:=x1;r:=x2;k:=y1;end;
        inc(ly);
        with y[ly] do begin l:=x1;r:=x2;k:=y2;p:=1;end;
      end;
  end;
procedure qsort(var a:arr;l,r:longint);
var
  i,j,m:Longint;
  p:cc;
begin
  i:=l;j:=r;m:=a[(l+r)shr 1].k;
  repeat
    while a[i].k<m do inc(i);
    while a[j].k>m do dec(j);
    if i<=j then
    begin
      p:=a[i];
      a[i]:=a[j];
      a[j]:=p;
      inc(i);
      dec(j);
    end;
  until i>j;
  if i<r then qsort(a,i,r);
  if j>l then qsort(a,l,j);
end;
procedure new(root:Longint);
  begin
        tr[root].ld:=tr[root*2].ld;
        tr[root].rd:=tr[root*2+1].rd;
        tr[root].line:=tr[root*2].line+tr[root*2+1].line-tr[root*2].rd*tr[root*2+1].ld;

  end;
procedure ins(root,a,b:Longint);
  begin
  with tr[root] do
    if (l>=a)and(r<=b)then
      begin
        inc(c);
        ld:=1;
        rd:=1;
        line:=1;
      end
      else
      begin
        if a<m then ins(root*2,a,b);
        if b>m then ins(root*2+1,a,b);
        if c=0 then new(root);
      end;
  end;
procedure del(root,a,b:longint);
begin
  with tr[root] do
    if (l>=a)and(r<=b) then
      begin
        dec(c);
        if c=0 then  new(root);
      end
      else
       begin
         if a<m then del(root*2,a,b);
         if b>m then del(root*2+1,a,b);
         if c=0 then new(root);
       end;
end;
procedure build(tt,l,r:Longint);
  begin
    tr[tt].m:=(l+r)div 2;
    tr[tt].l:=l;
    tr[tt].r:=r;
    if r-l=1 then exit;
    build(tt*2,l,tr[tt].m);
    build(tt*2+1,tr[tt].m,r);
  end;
procedure calc(var a:arr);
  begin
    for i:=1 to 2*n-1 do
      begin
        if a[i].p=0 then ins(1,a[i].l,a[i].r)else del(1,a[i].l,a[i].r);
        ans:=tr[1].line*(a[i+1].k-a[i].k)+ans;
      end;


  end;
begin
  init;
  qsort(x,1,n shl 1);
  ans:=0;

  fillchar(tr,sizeof(tr),0);
  build(1,miny,maxy);

  calc(x);
  fillchar(tr,sizeof(tr),0);
  qsort(y,1,n shl 1);
  build(1,minx,maxx);
  calc(y);
  writeln(ans*2);
end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator