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

为什么我离散化还TLE,讨论里的数据我都能过,但是就是TLE,求神牛help!!

Posted by heshibidahe at 2012-03-16 12:32:28 on Problem 2528
线段树+离散化,就是TLE,请求帮助。
从后往前处理每个海报,如果贴上就记录,并ans++。
type
 node=record
  l,r,lc,rc,z:longint;
 end;
 node2=record
  num,belong:longint;
 end;
var
 tree:array[0..20001] of node;
 post:array[1..10000,0..1] of longint;
 po:array[0..20001] of node2;
 i,j,k,n,p,ans,x,t,tt:longint; quit:boolean;
procedure qsort(l,r:longint);
var
 i,j,x:longint; t:node2;
begin
 i:=l; j:=r; x:=po[random(r-l)+l].num;
 repeat
  while po[i].num<x do inc(i);
  while po[j].num>x do dec(j);
  if i<=j then
   begin
    t:=po[i]; po[i]:=po[j]; po[j]:=t;
    inc(i); dec(j);
   end;
 until i>j;
 if i<r then qsort(i,r);
 if j>l then qsort(l,j);
end;
procedure build(var t:longint; l,r:longint);
begin
 inc(tt); t:=tt;
 tree[t].l:=l; tree[t].r:=r;
 tree[t].z:=0;
 if l<r then
  begin
   build(tree[t].lc,l,(l+r)>>1);
   build(tree[t].rc,(l+r)>>1+1,r);
  end;
end;
procedure insert(var t:longint;l,r:longint);
begin
 if t=0 then exit;
 if tree[t].z>0 then exit;
 if tree[t].z=-1 then
  begin
   if tree[tree[t].lc].r>=r then insert(tree[t].lc,l,r) else
   if tree[tree[t].rc].l<=l then insert(tree[t].rc,l,r) else
    begin
     insert(tree[t].lc,l,tree[tree[t].lc].r);
     insert(tree[t].rc,tree[tree[t].rc].l,r);
    end;
   exit;
  end;
 if (tree[t].l=l) and (tree[t].r=r) then
  begin
   quit:=true;
   tree[t].z:=i;
  end else
  begin
   tree[t].z:=-1;
   if tree[tree[t].lc].r>=r then insert(tree[t].lc,l,r) else
   if tree[tree[t].rc].l<=l then insert(tree[t].rc,l,r) else
    begin
     insert(tree[t].lc,l,tree[tree[t].lc].r);
     insert(tree[t].rc,tree[tree[t].rc].l,r);
    end;
  end;
end;
procedure main;
begin
 readln(n);
 po[0].num:=0;
 for i:=1 to n do
  begin
   readln(post[i][0],post[i][1]);
   po[i+i-1].num:=post[i][0]; po[i+i-1].belong:=i;
   po[i+i].num:=post[i][1]; po[i+i].belong:=-i
  end;
 qsort(1,n+n);
 p:=0;
 for i:=1 to n+n do
  begin
   if po[i].num<>po[i-1].num then inc(p);
   x:=po[i].belong;
   if x>0 then post[x,0]:=p else post[-x,1]:=p;
  end;
 //prepare finsih
 t:=0; tt:=0; ans:=0;
 build(t,1,p);
 for i:=n downto 1 do
  begin
   quit:=false;
   insert(t,post[i][0],post[i][1]);
   if quit then inc(ans);
  end;
 writeln(ans);
end;
begin
 randomize;
 readln(k);
 for j:=1 to k do main;
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