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 |
Re:能帮我看看吗? 你们的数据我都过了,不过还是Wa!In Reply To:Re:觉得这样的数据更准确一点 Posted by:liulingling at 2009-08-10 15:02:09 #include <stdio.h> int L,T,Q; struct Tree { int left; int right; int color; }t[500000]; int lone(int i) { return i&(i-1); } void f(int pos) { while(pos!=1) { int temp=pos; if(pos%2==1)pos=(pos-1)/2; else pos=pos/2; t[pos].color=(t[pos*2+1].color)|(t[pos*2].color); } } void build(int left,int right,int step) { t[step].left=left; t[step].right=right; t[step].color=1; if(left==right)return ; int mid=(left+right)/2; build(left,mid,step*2); build(mid+1,right,step*2+1); } void color(int left,int right,int step,int c) { int mid=(t[step].left+t[step].right)/2; if(left<=t[step].left&&right>=t[step].right) { t[step].color=c; f(step); return ; } if(t[step].color==c)return ; if(lone(t[step].color)==0) { t[step*2].color=t[step].color; t[step*2+1].color=t[step].color; } if(mid>=right) { color(left,right,2*step,c); } else if(mid<left) { color(left,right,2*step+1,c); } else { color(left,mid,2*step,c); color(mid+1,right,2*step+1,c); } t[step].color=t[step*2].color | t[step*2+1].color; } void search(int left,int right,int step,int &cnt) { int mid; if(left<=t[step].left&&right>=t[step].right) { cnt|=t[step].color; return; } mid=(t[step].left+t[step].right)/2; if(mid>=right) {search(left,right,step*2,cnt);} else if(mid<left)search(left,right,step*2+1,cnt); else { search(left,mid,2*step,cnt); search(mid+1,right,2*step+1,cnt); } } int count(int c)// 统计 { int i,cnt=0; for(i=1;i<=30;i++) { int temp=c%2; c/=2; if(temp) cnt++; } return cnt; } int main() { int a,b,c; char ch; scanf("%d %d %d",&L,&T,&Q); build(1,L,1);//建树 while(Q--) { getchar(); scanf("%c",&ch); if(ch=='C') { int p=1; scanf("%d %d %d",&a,&b,&c); if(a>b) a^=b^=a^=b; while(--c) p*=2; color(a,b,1,p);// 染色 } else { scanf("%d %d",&a,&b); if(a>b) a^=b^=a^=b; int cnt=0; search(a,b,1,cnt); // printf("cnt : %d\n",cnt); printf("%d\n",count(cnt)); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator