1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | const int N = 1024; struct Qua{ int x, y, X, Y, len; char val; Qua *nxt[4]; }; void build( int x, int y, int X, int Y, Qua* cur){ cur->x = x; cur->y = y; cur->X = X; cur->Y = Y; if ( X-x == 1 && Y - y == 1){ cur->val = -1; cur->x = x; cur->y = y; cur->X = X; cur->Y = Y; return ; } if ( X-x < 1 ) return ; if ( Y-y < 1 ) return ; int mx = (x+X)/2, my = (y+Y)/2; build(x,y,mx,my, cur->nxt[0] = new Qua); build(mx,my,X,Y, cur->nxt[1] = new Qua); build(mx,y,X,my, cur->nxt[2] = new Qua); build(x,my,mx,Y, cur->nxt[3] = new Qua); } void update( int x, int y, int X, int Y, Qua* cur, char color){ if ( X <= cur->x || cur->X <= x || Y <= cur->y || cur->Y <= y ) return ; x = max(x,cur->x); X = min(X,cur->X); y = max(y,cur->y); Y = min(Y,cur->Y); if ( x == cur->x && X == cur->X && y == cur->y && Y == cur->Y ){ cur->val = color; return ; } if ( cur->val != -1 )Rep(i,4)cur->nxt[i]->val = cur->val; cur->val = -1; // 清除懒惰标志,不能忘记 Rep(i,4)update(x,y,X,Y,cur->nxt[i],color); } int get(Qua* cur){ if ( cur->val != -1 ) return cur->val == 'w' ? (cur->Y-cur->y)*(cur->X-cur->x) : 0; int ans = 0; Rep(i,4)ans += get(cur->nxt[i]); return ans; } |