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

求数据

Posted by ghk at 2009-01-13 18:48:29 on Problem 2482
wa得不行了。。。。。。。。。
边界、int64、n=0都考虑了。。。。。。。
var n,w,h,i,j,ro,nn,ans:longint;
    t:array[0..20001] of record key:int64; le,ri,pri,mm,ms,cnt,num:longint; end;
    b:array[1..10001] of longint;
    a:array[0..10001] of record x,y:int64; c:longint; end;
function max(const x,y:longint):longint;
begin if x>y then exit(x) else exit(y); end;
procedure q(const l,r:longint);
var ii,jj,tt:longint;
    x:int64;
begin
 ii:=l; jj:=r;
 x:=a[b[(l+r) shr 1]].x;
 repeat
  while a[b[ii]].x<x do inc(ii);
  while x<a[b[jj]].x do dec(jj);
  if ii<=jj
   then begin
         tt:=b[ii]; b[ii]:=b[jj]; b[jj]:=tt;
         inc(ii); dec(jj);
        end;
 until ii>jj;
 if l<jj then q(l,jj);
 if ii<r then q(ii,r);
end;
procedure updata(const x:longint);
begin
 t[x].mm:=t[t[x].le].mm+t[t[x].ri].mm+t[x].cnt;
 t[x].ms:=max(t[t[x].le].ms,
 max(t[x].mm-t[t[x].ri].mm,t[x].mm-t[t[x].ri].mm+t[t[x].ri].ms));
end;
procedure lt(var x:longint);
var y:longint;
begin
 y:=t[x].ri;
 t[x].ri:=t[y].le;
 t[y].le:=x;
 updata(x);
 updata(y);
 x:=y;
end;
procedure rt(var x:longint);
var y:longint;
begin
 y:=t[x].le;
 t[x].le:=t[y].ri;
 t[y].ri:=x;
 updata(x);
 updata(y);
 x:=y;
end;
procedure insert(var x:longint;const kk:int64; cc:longint);
begin
 if x=0
  then begin
        inc(nn);
        with t[nn] do
         begin
          key:=kk; cnt:=cc; num:=1;
          pri:=random(maxlongint);
         end;
        x:=nn;
       end
  else begin
        if kk<t[x].key
         then begin
               insert(t[x].le,kk,cc);
               if t[t[x].le].pri>t[x].pri then rt(x);
              end
         else if kk>t[x].key
               then begin
                     insert(t[x].ri,kk,cc);
                     if t[t[x].ri].pri>t[x].pri then lt(x);
                    end
               else begin
                     inc(t[x].cnt,cc);
                     inc(t[x].num);
                    end;
       end;
 updata(x);
end;
procedure delete(var x:longint;const kk:int64; cc:longint);
begin
 if kk<t[x].key
  then delete(t[x].le,kk,cc)
  else if kk>t[x].key
        then delete(t[x].ri,kk,cc)
        else if t[x].num>1
              then begin
                    dec(t[x].num);
                    dec(t[x].cnt,cc);
                   end
              else begin
                    if t[x].le+t[x].ri=0
                     then x:=0
                     else begin
                           if t[t[x].le].pri>t[t[x].ri].pri
                            then rt(x) else lt(x);
                           delete(x,kk,cc);
                          end;
                   end;
 updata(x);
end;
begin    
 repeat
  read(n,w,h);
  if n=0 then begin writeln(0); continue; end;
  for i:=1 to n do
   with a[i] do
    begin
     read(x,y,c);
     b[i]:=i;
    end;
  q(1,n);
  i:=0; j:=0; nn:=0;
  fillchar(t,sizeof(t),0);
  ro:=0; t[0].pri:=-1;
  b[n+1]:=0; a[0].x:=maxlongint*2;
  repeat
   if i>0
    then begin
          delete(ro,a[b[i]].y,a[b[i]].c);
          delete(ro,a[b[i]].y+int64(h),-a[b[i]].c);
         end;
   inc(i);
   while a[b[j+1]].x-a[b[i]].x<w do
    begin
     inc(j);
     insert(ro,a[b[j]].y,a[b[j]].c);
     insert(ro,a[b[j]].y+int64(h),-a[b[j]].c);
    end;
   ans:=max(t[ro].ms,ans);
  until (i=j) or (j=n);
  writeln(ans);
 until seekeof;
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