Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
。。为什么这个程序会TLE一版呢 求大牛帮忙#include <iostream> #include <algorithm> #include <stdio.h> using namespace std; int t,n,l[100000],r[100000]; int cover[100000],d[100500],num; int lx[12000],rx[12000],hash[10000100]; void build(int x,int ll,int rr) { l[x]=ll,r[x]=rr; cover[x]=0; if(rr>ll) { int mid=(ll+rr)>>1; build(x<<1,ll,mid); build((x<<1)+1,mid+1,rr);//需开成有交点的 } } int insert(int x,int ll,int rr) { if(cover[x]>0)return false; if(!cover[x]&&ll<=l[x]&&r[x]<=rr)return cover[x]=1; int mid=(l[x]+r[x])>>1; int k1=0,k2=0; if(rr<=mid) k1=insert(x<<1,ll,rr); else if(ll>mid) k2=insert((x<<1)+1,ll,rr); else k1=insert(x<<1,ll,mid)+insert((x<<1)+1,mid+1,rr); if(k1||k2){cover[x]=-1;return true;} return false; } int main() { scanf("%d",&t); for(;t;t--) { scanf("%d",&n); int cnt=0; for(int i=1;i<=n;i++) { scanf("%d %d",&lx[i],&rx[i]); d[cnt+1]=lx[i],d[cnt+2]=rx[i]; cnt+=2; } sort(d+1,d+cnt+1); num=0; for(int i=1;i<=cnt;i++) if(d[i]!=d[i-1]) { if(d[i]>d[i-1]+1)++num; hash[d[i]]=++num; } build(1,1,num); int ans=0; for(int i=n;i>=1;i--) if(insert(1,hash[lx[i]],hash[rx[i]]))ans++; cout<<ans<<endl; } //system("pause"); return 0; } 程序的答案没有错 我拿官方数据测过了 但是狂TLe 崩溃。。。 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator