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实在看不出来了#include <stdio.h> #include <string.h> struct tree { int left,right; int dif; //每一位代表一种颜色 tree * lchild,* rchild; void construct(int l,int r); void update(int l,int r,int c); int cal(int l,int r); }stree[500001],*root=&stree[0]; int len; int L,T,N; void tree::construct(int l,int r) { left=l; right=r; dif=1; if(l==r) lchild=rchild=NULL ; else { lchild=&stree[len++]; rchild=&stree[len++]; int mid=(l+r)>>1; lchild->construct(l,mid); rchild->construct(mid+1,r); } } void tree::update(int l,int r,int c) { if(lchild&&r<=lchild->right) lchild->update(l,r,c); else if(rchild&&l>=rchild->left) rchild->update(l,r,c); else if(lchild&&rchild) { lchild->update(l,lchild->right,c); rchild->update(rchild->left,r,c); } if(lchild==NULL&&rchild==NULL) { dif=1<<(c-1); } else if(lchild&&rchild) { dif=(lchild->dif)|(rchild->dif); } } int tree::cal(int l,int r) { if(l==left&&r==right) return dif; else { if(r<=lchild->right) return lchild->cal(l,r); else if(l>=rchild->left) return rchild->cal(l,r); else { return (lchild->cal(l,lchild->right))|(rchild->cal(rchild->left,r)); } } } int main() { char com[4]; int x,y,c; int i; while (scanf("%d%d%d",&L,&T,&N)==3) { len=1; root->construct(1,L); for (i=0;i<N;i++) { scanf("%s",com); if(strcmp(com,"C")==0) { scanf("%d%d%d",&x,&y,&c); root->update(x,y,c); } else { scanf("%d%d",&x,&y); int kind=(root->cal(x,y)); int count=0; while (kind) { if(kind%2) count++; kind>>=1; } printf("%d\n",count); } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator