题意:一个矩阵元素均为0,1, 快速更新指定的子矩阵,快速询问的是一个点。
他人具体代码:
View Code
#include#include #include #include using namespace std;#define maxn 1005int c[maxn][maxn];int Row, Col;inline int Lowbit(const int &x){ return x & (-x);}int Sum(int i, int j){ int tempj, sum = 0; while (i > 0) { tempj = j; while (tempj > 0) { sum += c[i][tempj]; tempj -= Lowbit(tempj); } i -= Lowbit(i); } return sum;}void Update(int i, int j, int num){ int tempj; while (i <= Row) { tempj = j; while (tempj <= Col) { c[i][tempj] += num; tempj += Lowbit(tempj); } i += Lowbit(i); }}int main(){ int x, n, t; scanf("%d", &x); while (x--) { memset(c, 0, sizeof(c)); scanf("%d%d", &n, &t); getchar(); Row = n; Col = n; for (int i = 0; i < t; i++) { char ch; int x1, x2, y2, y1; scanf("%c", &ch); if (ch == 'C') { scanf("%d%d%d%d", &x1, &y1, &x2, &y2); x2++; y2++; Update(x1, y1, 1); Update(x1, y2, -1); Update(x2, y1, -1); Update(x2, y2, 1); } else { scanf("%d%d", &x1, &y1); printf("%d\n", (1 & Sum(x1, y1))); } getchar(); } printf("\n"); } return 0;}