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 |
大家都在说离散化的问题,只要不离散化不就好了?RT动态开点线段树他不香吗? AC代码: #include<cstdio> #include<queue> #include<iostream> #include<cstring> #include<algorithm> using namespace std; int T,n,cnt,rt,vis[10001],ans; struct tree { int l,r,tag; }t[10000001]; void change(int l,int r,int &rt,int L,int R,int k) { if(!rt)rt=++cnt,t[cnt].l=t[cnt].r=t[cnt].tag=0; if(L<=l&&r<=R) { t[rt].tag=k; return; } if(t[rt].tag) { if(!t[rt].l)t[rt].l=++cnt,t[cnt].l=t[cnt].r=t[cnt].tag=0; t[t[rt].l].tag=t[rt].tag; if(!t[rt].r)t[rt].r=++cnt,t[cnt].l=t[cnt].r=t[cnt].tag=0; t[t[rt].r].tag=t[rt].tag; t[rt].tag=0; } int mid=(l+r)>>1; if(L<=mid)change(l,mid,t[rt].l,L,R,k); if(R>mid)change(mid+1,r,t[rt].r,L,R,k); } void ask(int l,int r,int rt) { if(!rt)return; if(t[rt].tag) { if(!vis[t[rt].tag]) vis[t[rt].tag]=1,ans++; return; } int mid=(l+r)>>1; ask(l,mid,t[rt].l); ask(mid+1,r,t[rt].r); } int main() { scanf("%d",&T); while(T--) { cnt=rt=ans=0; memset(vis,0,sizeof(vis)); scanf("%d",&n); for(int i=1;i<=n;i++) { int l,r; scanf("%d%d",&l,&r); change(1,10000000,rt,l,r,i); } ask(1,10000000,rt); printf("%d\n",ans); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator