Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12 Accepted Submission(s): 3
//1010 #include<stdio.h> #include<iostream> #include<algorithm> #include<string.h> #include<stdlib.h> #include<math.h> using namespace std; const int MAXN=60010; struct Node { int l,r; int cr,cg,cb; int lf,rf; int lr,lg,lb,lrg,lrb,lgb,lrgb; int lw; }segTree[MAXN*6]; struct Line { int x; int y1,y2; int flag; int f; }line[MAXN]; int y[MAXN]; bool cmp(Line a,Line b) { return a.x<b.x; } void Build(int i,int l,int r) { segTree[i].l=l; segTree[i].r=r; segTree[i].lf=y[l]; segTree[i].rf=y[r]; segTree[i].cr=segTree[i].cg=segTree[i].cb=0; segTree[i].lw=segTree[i].rf-segTree[i].lf; segTree[i].lr=segTree[i].lg=segTree[i].lb=segTree[i].lrg=segTree[i].lgb=segTree[i].lrb=segTree[i].lrgb=0; if(l+1==r)return; int mid=((l+r)>>1); Build(i<<1,l,mid); Build((i<<1)|1,mid,r); } void calc(int i) { if(segTree[i].l+1==segTree[i].r) { if(segTree[i].cr>0&&segTree[i].cg>0&&segTree[i].cb>0) { segTree[i].lrgb=segTree[i].rf-segTree[i].lf; segTree[i].lr=segTree[i].lg=segTree[i].lb=segTree[i].lrg=segTree[i].lgb=segTree[i].lrb=0; segTree[i].lw=0; } else if(segTree[i].cr>0&&segTree[i].cg>0) { segTree[i].lrg=segTree[i].rf-segTree[i].lf; segTree[i].lr=segTree[i].lg=segTree[i].lb=segTree[i].lrgb=segTree[i].lgb=segTree[i].lrb=0; segTree[i].lw=0; } else if(segTree[i].cr>0&&segTree[i].cb>0) { segTree[i].lrb=segTree[i].rf-segTree[i].lf; segTree[i].lr=segTree[i].lg=segTree[i].lb=segTree[i].lrgb=segTree[i].lgb=segTree[i].lrg=0; segTree[i].lw=0; } else if(segTree[i].cg>0&&segTree[i].cb>0) { segTree[i].lgb=segTree[i].rf-segTree[i].lf; segTree[i].lr=segTree[i].lg=segTree[i].lb=segTree[i].lrgb=segTree[i].lrb=segTree[i].lrg=0; segTree[i].lw=0; } else if(segTree[i].cr>0) { segTree[i].lr=segTree[i].rf-segTree[i].lf; segTree[i].lg=segTree[i].lb=segTree[i].lrg=segTree[i].lgb=segTree[i].lrb=segTree[i].lrgb=0; segTree[i].lw=0; } else if(segTree[i].cg>0) { segTree[i].lw=0; segTree[i].lg=segTree[i].rf-segTree[i].lf; segTree[i].lr=segTree[i].lb=segTree[i].lrg=segTree[i].lgb=segTree[i].lrb=segTree[i].lrgb=0; } else if(segTree[i].cb>0) { segTree[i].lb=segTree[i].rf-segTree[i].lf; segTree[i].lw=0; segTree[i].lg=segTree[i].lr=segTree[i].lrg=segTree[i].lgb=segTree[i].lrb=segTree[i].lrgb=0; } else { segTree[i].lb=0; segTree[i].lw=segTree[i].rf-segTree[i].lf; segTree[i].lg=segTree[i].lr=segTree[i].lrg=segTree[i].lgb=segTree[i].lrb=segTree[i].lrgb=0; } return; } if(segTree[i].cr>0&&segTree[i].cg>0&&segTree[i].cb>0) { segTree[i].lrgb=segTree[i].rf-segTree[i].lf; segTree[i].lr=segTree[i].lg=segTree[i].lb=segTree[i].lrg=segTree[i].lgb=segTree[i].lrb=0; segTree[i].lw=0; return; } else if(segTree[i].cr>0&&segTree[i].cg>0) { segTree[i].lr=0; segTree[i].lg=0; segTree[i].lw=0; segTree[i].lb=0; segTree[i].lrg=segTree[i<<1].lw+segTree[(i<<1)|1].lw+segTree[i<<1].lr+segTree[(i<<1)|1].lr +segTree[i<<1].lg+segTree[(i<<1)|1].lg +segTree[i<<1].lrg+segTree[(i<<1)|1].lrg; segTree[i].lrb=segTree[i].lgb=0; segTree[i].lrgb=segTree[i<<1].lb+segTree[i<<1].lrb+segTree[i<<1].lgb+segTree[i<<1].lrgb +segTree[(i<<1)|1].lb+segTree[(i<<1)|1].lrb+segTree[(i<<1)|1].lgb+segTree[(i<<1)|1].lrgb; } else if(segTree[i].cr>0&&segTree[i].cb>0) { segTree[i].lr=0; segTree[i].lg=0; segTree[i].lw=0; segTree[i].lb=0; segTree[i].lrb=segTree[i<<1].lw+segTree[(i<<1)|1].lw+segTree[i<<1].lr+segTree[(i<<1)|1].lr +segTree[i<<1].lb+segTree[(i<<1)|1].lb +segTree[i<<1].lrb+segTree[(i<<1)|1].lrb; segTree[i].lrg=segTree[i].lgb=0; segTree[i].lrgb=segTree[i<<1].lg+segTree[i<<1].lgb+segTree[i<<1].lrg+segTree[i<<1].lrgb +segTree[(i<<1)|1].lg+segTree[(i<<1)|1].lgb+segTree[(i<<1)|1].lrg+segTree[(i<<1)|1].lrgb; } else if(segTree[i].cg>0&&segTree[i].cb>0) { segTree[i].lr=0; segTree[i].lg=0; segTree[i].lw=0; segTree[i].lb=0; segTree[i].lgb=segTree[i<<1].lw+segTree[(i<<1)|1].lw+segTree[i<<1].lg+segTree[(i<<1)|1].lg +segTree[i<<1].lb+segTree[(i<<1)|1].lb +segTree[i<<1].lgb+segTree[(i<<1)|1].lgb; segTree[i].lrg=segTree[i].lrb=0; segTree[i].lrgb=segTree[i<<1].lr+segTree[i<<1].lrb+segTree[i<<1].lrg+segTree[i<<1].lrgb +segTree[(i<<1)|1].lr+segTree[(i<<1)|1].lrb+segTree[(i<<1)|1].lrg+segTree[(i<<1)|1].lrgb; } else if(segTree[i].cr>0) { segTree[i].lr=segTree[i<<1].lw+segTree[i<<1].lr +segTree[(i<<1)|1].lw+segTree[(i<<1)|1].lr; segTree[i].lw=segTree[i].lg=segTree[i].lb=0; segTree[i].lgb=0; segTree[i].lrg=segTree[i<<1].lg+segTree[i<<1].lrg +segTree[(i<<1)|1].lg+segTree[(i<<1)|1].lrg; segTree[i].lrb=segTree[i<<1].lb+segTree[i<<1].lrb +segTree[(i<<1)|1].lb+segTree[(i<<1)|1].lrb; segTree[i].lrgb=segTree[i<<1].lgb+segTree[i<<1].lrgb +segTree[(i<<1)|1].lgb+segTree[(i<<1)|1].lrgb; } else if(segTree[i].cg>0) { segTree[i].lg=segTree[i<<1].lw+segTree[i<<1].lg +segTree[(i<<1)|1].lw+segTree[(i<<1)|1].lg; segTree[i].lw=segTree[i].lr=segTree[i].lb=0; segTree[i].lrb=0; segTree[i].lrg=segTree[i<<1].lr+segTree[i<<1].lrg +segTree[(i<<1)|1].lr+segTree[(i<<1)|1].lrg; segTree[i].lgb=segTree[i<<1].lb+segTree[i<<1].lgb +segTree[(i<<1)|1].lb+segTree[(i<<1)|1].lgb; segTree[i].lrgb=segTree[i<<1].lrb+segTree[i<<1].lrgb +segTree[(i<<1)|1].lrb+segTree[(i<<1)|1].lrgb; } else if(segTree[i].cb>0) { segTree[i].lb=segTree[i<<1].lw+segTree[i<<1].lb +segTree[(i<<1)|1].lw+segTree[(i<<1)|1].lb; segTree[i].lw=segTree[i].lr=segTree[i].lg=0; segTree[i].lrg=0; segTree[i].lrb=segTree[i<<1].lr+segTree[i<<1].lrb +segTree[(i<<1)|1].lr+segTree[(i<<1)|1].lrb; segTree[i].lgb=segTree[i<<1].lg+segTree[i<<1].lgb +segTree[(i<<1)|1].lg+segTree[(i<<1)|1].lgb; segTree[i].lrgb=segTree[i<<1].lrg+segTree[i<<1].lrgb +segTree[(i<<1)|1].lrg+segTree[(i<<1)|1].lrgb; } else { segTree[i].lw=segTree[i<<1].lw+segTree[(i<<1)|1].lw; segTree[i].lr=segTree[i<<1].lr+segTree[(i<<1)|1].lr; segTree[i].lg=segTree[i<<1].lg+segTree[(i<<1)|1].lg; segTree[i].lb=segTree[i<<1].lb+segTree[(i<<1)|1].lb; segTree[i].lrg=segTree[i<<1].lrg+segTree[(i<<1)|1].lrg; segTree[i].lgb=segTree[i<<1].lgb+segTree[(i<<1)|1].lgb; segTree[i].lrb=segTree[i<<1].lrb+segTree[(i<<1)|1].lrb; segTree[i].lrgb=segTree[i<<1].lrgb+segTree[(i<<1)|1].lrgb; } } void update(int i,Line e) { if(e.y1==segTree[i].lf&&e.y2==segTree[i].rf) { if(e.flag==1) { segTree[i].cr+=e.f; } else if(e.flag==2) { segTree[i].cg+=e.f; } else if(e.flag==3) { segTree[i].cb+=e.f; } //printf("*%d %d\n",segTree[i].lf,segTree[i].rf); // printf("**%d %d %d\n",segTree[i].cr,segTree[i].cg,segTree[i].cb); calc(i); return; } if(e.y2<=segTree[i<<1].rf) update(i<<1,e); else if(e.y1>=segTree[(i<<1)|1].lf) update((i<<1)|1,e); else { Line temp=e; temp.y2=segTree[i<<1].rf; update(i<<1,temp); temp=e; temp.y1=segTree[(i<<1)|1].lf; update((i<<1)|1,temp); } calc(i); } long long out[20]; int main() { // freopen("J.in","r",stdin); // freopen("J.out","w",stdout); int x1,x2,y1,y2; char str[10]; int T; int n; scanf("%d",&T); int iCase=0; while(T--) { iCase++; scanf("%d",&n); int t=1; for(int i=1;i<=n;i++) { scanf("%s",&str); scanf("%d%d%d%d",&x1,&y1,&x2,&y2); line[t].x=x1; line[t].y1=y1; line[t].y2=y2; line[t].f=1; if(str[0]=='R')line[t].flag=1; else if(str[0]=='G')line[t].flag=2; else line[t].flag=3; y[t]=y1; t++; line[t].x=x2; line[t].y1=y1; line[t].y2=y2; line[t].f=-1; y[t]=y2; if(str[0]=='R')line[t].flag=1; else if(str[0]=='G')line[t].flag=2; else line[t].flag=3; t++; } sort(line+1,line+t,cmp); sort(y+1,y+t); Build(1,1,t-1); memset(out,0,sizeof(out)); update(1,line[1]); for(int i=2;i<t;i++) { out[1]+=(long long)segTree[1].lr*(line[i].x-line[i-1].x); out[2]+=(long long)segTree[1].lg*(line[i].x-line[i-1].x); out[3]+=(long long)segTree[1].lb*(line[i].x-line[i-1].x); out[4]+=(long long)segTree[1].lrg*(line[i].x-line[i-1].x); out[5]+=(long long)segTree[1].lrb*(line[i].x-line[i-1].x); out[6]+=(long long)segTree[1].lgb*(line[i].x-line[i-1].x); out[7]+=(long long)segTree[1].lrgb*(line[i].x-line[i-1].x); update(1,line[i]); } printf("Case %d:\n",iCase); for(int i=1;i<=7;i++) printf("%I64d\n",out[i]); } return 0; }