登 录
搞得好囧,想自己A,结果还是盗版货,而且郁闷了好久才见ac的,擦擦。。。
ps:
本来也想这么做的:每次染色的时候,并不更新到子节点,而是把信息上次的和目前的信息综合之后,再判断是否向下更新的,结果,采用基本做法,TLE到死........
#include<stdio.h> #include<string.h> #define max 100005 struct node { int l,r; int color; }st[max*4]; bool co[35]; int L,T,O,ans; void create(int l,int r,int i) { st[i].color =1; st[i].l=l;st[i].r =r; if(st[i].l ==st[i].r ) return ; int mid=(st[i].l+st[i].r)>>1; create(l,mid,i*2); create(mid+1,r,i*2+1); } void update(int l,int r,int col,int i) { if(st[i].color ==col) return ; if(l==st[i].l&&st[i].r==r) { st[i].color=col; return ; } if(st[i].color >0) { st[i<<1].color =st[i].color ; st[(i<<1)+1].color =st[i].color; st[i].color =-1; } int mid=(st[i].l+st[i].r)>>1; if(r<=mid) update(l,r,col,i*2); else if(l>mid) update(l,r,col,i*2+1); else { update(l,mid,col,i*2); update(mid+1,r,col,i*2+1); } } void search(int l,int r,int i) { if(st[i].color >0) { co[st[i].color ]=true; return ; } int mid=(st[i].l +st[i].r )>>1; if(r<=mid) search(l,r,i*2); else if(l>mid) search(l,r,i*2+1); else { search(l,mid,i*2); search(mid+1,r,i*2+1); } } int main() { int i,x,y,z,k; char c; scanf("%d%d%d",&L,&T,&O); create(1,L,1); for(i=0;i<O;i++) { getchar(); scanf("%c",&c); if(c=='C') { scanf("%d%d%d",&x,&y,&z); if(x>y){k=x;x=y;y=k;} update(x,y,z,1); } else { ans=0; scanf("%d%d",&x,&y); if(x>y){k=x;x=y;y=k;} memset(co,false,sizeof(co)); search(x,y,1); for(z=0;z<31;z++) if(co[z]) ans++; printf("%d/n",ans); } } return 0; }
抱歉!评论已关闭.