The question of the matrix building instructor.
The initial value of a matrix is 0, and the matrix is reversed for "C X1 Y1 X2 Y2" each time. Or the "Q X1 Y1" query point is 0/1.
The first time I came into contact with the questions about tree covers.
AC: for a basic line segment tree, create a line segment tree in the Y direction on each node. Tree [N] [m]
When this question is updated, the X direction is (x1, x2), and then Y1 and Y2 are updated on it.
For queries, from top to bottom to X1, y must be queried (the updated range must include this point), and y must be updated to y1.
# Include <stdio. h> # include <string. h> # define maxn 1005 # define MEM (a) memset (A, 0, sizeof (A) bool tree [maxn <2] [maxn <2]; int X, N, T; int num, x1, x2, Y1, Y2; char ch [10]; void updatey (int yl, int yr, int XP, int YP) {If (Y1 <= yl & yr <= Y2) {tree [XP] [YP] =! Tree [XP] [YP]; return;} int mid = (yl + yr)> 1; if (Y1 <= mid) updatey (YL, mid, XP, YP <1); If (Y2> mid) updatey (Mid + 1, YR, XP, YP <1 | 1);} void updatex (int xl, int XR, int XP) {If (X1 <= XL & XR <= x2) {updatey (1, n, XP, 1); return ;} int mid = (XL + XR)> 1; // The following sentence was written incorrectly at the beginning. According to build, it was an update operation... if (X1 <= mid) updatex (XL, mid, XP <1); If (X2> mid) updatex (Mid + 1, xr, XP <1 | 1);} void queryy (int yl, int yr, int XP, int YP) {num + = tree [XP] [YP]; if (yl = yr) Return; Int mid = (yl + yr)> 1; if (Y1 <= mid) queryy (YL, mid, XP, YP <1 ); else queryy (Mid + 1, YR, XP, YP <1 | 1);} void queryx (int xl, int XR, int XP) {queryy (1, n, XP, 1); If (XL = xr) return; int mid = (XL + XR)> 1; if (X1 <= mid) queryx (XL, mid, XP <1); else queryx (Mid + 1, xr, XP <1 | 1);} int main () {While (~ Scanf ("% d", & X) while (X --) {MEM (tree); scanf ("% d % * C", & N, & T); For (INT I = 0; I <t; I ++) {scanf ("% S % d", CH, & X1, & Y1 ); if (CH [0] = 'q') num = 0, queryx (1, n, 1), printf ("% d \ n", num % 2 ); else {scanf ("% d", & X2, & Y2); updatex (1, n, 1) ;}} if (X) printf ("\ n");} return 0 ;}
Poj 2155 decision tree-line segment Decision Tree