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 |
What the hell is wrong here?#include<cstdio> struct asdf{ int code,l,r,cont; }arr[263000]; int n,t,o,lim,x,y,z; void color(int p){ if(x<=arr[p].l&&arr[p].r<=y){ arr[p].code=(1<<z); arr[p].cont=0; return; } else if(y<arr[p].l||arr[p].r<x) return; else{ color(p*2); color(p*2+1); arr[p].code=arr[p*2].code|arr[p*2+1].code; arr[p].cont=(arr[p*2].cont|arr[p*2+1].cont)||(arr[p*2].code!=arr[p*2+1].code); } } void count(int p){ if(x<=arr[p].l&&arr[p].r<=y){ z|=arr[p].code; return; } else if(y<arr[p].l||arr[p].r<x) return; else{ if(!arr[p].cont){ arr[p*2].code=arr[p*2+1].code=arr[p].code; arr[p*2].cont=arr[p*2+1].cont=0; } count(p*2); count(p*2+1); } } int main(){ int i,j; char c; scanf("%d%d%d",&n,&t,&o); for(lim=1; lim<n; lim*=2); for(i=lim; i<2*lim; i++) arr[i].l=arr[i].r=i-lim+1,arr[i].code=1; for(i=lim-1; i>0; i--) arr[i].l=arr[i*2].l,arr[i].r=arr[i*2+1].r,arr[i].code=1; while(o--){ scanf("\n%c",&c); if(c=='C'){ scanf("%d%d%d",&x,&y,&z); z--; if(x>y) i=x,x=y,y=i; color(1); } else if(c=='P'){ scanf("%d%d",&x,&y); z=0; if(x>y) i=x,x=y,y=i; count(1); for(i=0,j=0; i<t; i++){ if(z&(1<<i)) j++; } printf("%d\n",j); } } return 0; } I used interval tree by recursive func.. I don't think it has any error on that Please find counter input Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator