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

p2481,我老是Runtime Time Error!WHY???

Posted by lijian2007 at 2007-07-10 12:38:20
program p2481;
const maxn=100000;
var c:array[0..maxn] of longint;
    x,y,num,ans:array[1..maxn] of longint;
    i,k,n:longint;

function lowbit(x:longint):longint;
 begin
     lowbit:=x and (x xor (x-1));
 end;

function getsum(x:longint):longint;
 var sum:longint;
 begin
     sum:=0;
     while x>0 do begin
         sum:=sum+c[x];
         x:=x-lowbit(x);
     end;
     getsum:=sum;
 end;

procedure change(x:longint);
 begin
     while x<=maxn do begin
         inc(c[x]);
         x:=x+lowbit(x);
     end;
 end;

procedure sort(l,r:longint);
 var i,j,k1,k2,t:longint;
 begin
     i:=l; j:=r; k1:=x[random(j-i+1)+i]; k2:=y[random(j-i+1)+i];
     repeat
        while (x[i]<k1) or ((x[i]=k1) and (y[i]>k2)) do inc(i);
        while (x[j]>k1) or ((x[j]=k1) and (y[j]<k2)) do dec(j);
        if i<=j then begin
            t:=x[i]; x[i]:=x[j]; x[j]:=t;
            t:=y[i]; y[i]:=y[j]; y[j]:=t;
            t:=num[i]; num[i]:=num[j]; num[j]:=t;
            inc(i); dec(j);
        end;
     until i>j;
     if l<j then sort(l,j);
     if i<r then sort(i,r);
 end;

begin
    readln(n); randomize;
    while n<>0 do begin
        fillchar(c,sizeof(c),0);
        for i:=1 to n do begin
            readln(x[i],y[i]);
            num[i]:=i;
            inc(y[i]);
        end;
        sort(1,n);
        for i:=1 to n do begin
            k:=getsum(y[i]-1);
            ans[num[i]]:=i-k-1;
            change(y[i]);
        end;
        for i:=1 to n-1 do write(ans[i],' ');
        writeln(ans[n]);
        readln(n);
    end;
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