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:2528 两个注意

Posted by Hoblovski at 2013-11-06 16:37:42 on Problem 2528
In Reply To:2528 两个注意 Posted by:Hoblovski at 2013-11-06 16:36:18
program poj2528;

type tnode=record
        col,l,r:longint;
     end;
     tline=record
        l,r,dl,dr:longint;
     end;

var t:array[1..200100] of tnode;
    line:array[1..100100] of tline;
    cort:array[1..200100] of longint;
    flag:array[1..100100] of boolean;
    n,crt,caseno:longint;

(*        This is really something ridiculous 'bout my RE        *)

function min(a,b:longint):longint; begin
if a<b then exit(a) else exit(b);  end;

function max(a,b:longint):longint; begin
if a>b then exit(a) else exit(b);  end;

procedure qsortcort(l,r:longint);
var i,j:longint;
    o,k:longint;
begin
i:=l; j:=r; o:=cort[l+random(r-l+1)];
repeat
while cort[i]<o do inc(i);
while cort[j]>o do dec(j);
if i<=j then begin
k:=cort[i]; cort[i]:=cort[j]; cort[j]:=k;
inc(i); dec(j);
end;
until i>j;
if i<r then qsortcort(i,r);
if j>l then qsortcort(l,j);
end;

procedure discret;
var i,j,k,oc:longint;
        function binfind(i:longint):longint;
        var l,r,mid:longint;
        begin
        l:=1; r:=crt;
        while l<>r do begin
                mid:=(l+r)>>1;
                if cort[mid]<i then l:=mid+1
                else if cort[mid]>i then r:=mid
                else exit(mid);
        end;
        exit(l);
        end;
begin
oc:=crt; crt:=1;
for i:=2 to oc do
        if cort[i]<>cort[crt] then begin
                inc(crt);
                cort[crt]:=cort[i];
        end;
for i:=1 to n do
        with line[i] do begin
                dl:=binfind(l);
                dr:=binfind(r);
        end;
end;

procedure init;
var i,j:longint;
begin
fillchar(flag,sizeof(flag),0);
fillchar(cort,sizeof(cort),0);
readln(n); crt:=0;
for i:=1 to n do begin
        with line[i] do
                readln(l,r);
        cort[crt+1]:=line[i].l;
        cort[crt+2]:=line[i].r;
        inc(crt,2);
end;
qsortcort(1,crt);
discret;
end;

procedure build(i,il,ir:longint);
var mid:longint;
begin
with t[i] do begin
        l:=il; r:=ir;
        col:=0;
end;
if il<>ir then begin
        mid:=(il+ir)>>1;
        build(i<<1,il,mid);
        build(i<<1+1,mid+1,ir);
end;
end;

procedure update(i:longint);
begin
if t[i].col>0 then begin
        t[i<<1].col:=t[i].col;
        t[i<<1+1].col:=t[i].col;
end;
end;

procedure ins(i,il,ir,ic:longint);
var mid:longint;
begin
update(i);
if (t[i].l=il)and(t[i].r=ir) then begin
        t[i].col:=ic;
end else begin
        mid:=(t[i].l+t[i].r)>>1;
        if il<=mid then ins(i<<1,il,min(mid,ir),ic);
        if ir>mid then ins(i<<1+1,max(mid+1,il),ir,ic);
        update(i<<1); update(i<<1+1);
        if (t[i<<1].col=-1)or(t[i<<1+1].col=-1) then t[i].col:=-1
        else if (t[i<<1].col=0) then t[i].col:=t[i<<1+1].col
        else if (t[i<<1+1].col=0) then t[i].col:=t[i<<1].col
        else if t[i<<1].col=t[i<<1+1].col then t[i].col:=t[i<<1].col
        else t[i].col:=-1;
end;
end;

procedure colour(i:longint);
begin
if t[i].col>0 then
        flag[t[i].col]:=true
else if t[i].col=-1 then begin
        colour(i<<1);
        colour(i<<1+1);
end;
end;

function indepcnt:longint;
var i,j:longint;
begin
j:=0;
for i:=1 to n do if flag[i] then inc(j);
exit(j);
end;

procedure work;
var i,j,k:longint;
begin
for i:=1 to n do
        ins(1,line[i].dl,line[i].dr,i);
colour(1);
writeln(indepcnt);
end;

begin
readln(caseno);
while caseno>0 do begin
        dec(caseno);
        init;
        build(1,1,crt);
        work;
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