Description
Given an n*n matrix A, whose elements is either 0 or 1. A[i, j] means the number in the I-th row and j-th column. Initially we have a[i, j] = 0 (1 <= i, J <= N).
We can change the matrix in the following. Given a rectangle whose upper-left corner is (x1, y1) and Lower-right Corner are (x2, y2), we change all the elements in th e Rectangle by using the "not" operation (if it was a ' 0 ' then change it to ' 1 ' otherwise change it into ' 0 '). To maintain the information of the matrix, you is asked to write a program to receive and execute both kinds of instructio Ns.
1. C x1 y1 x2 y2 (1 <= x1 <= x2 <= N, 1 <= y1 <= y2 <= n) changes the matrix by using the rectangle whos E upper-left Corner is (x1, y1) and Lower-right Corner are (x2, y2).
2. Q x Y (1 <= x, y <= N) querys a[x, y].
Input
The first line of the input was an integer X (x <=) representing the number of test cases. The following X blocks each represents a test case.
The first line of each block contains numbers n and T (2 <= n <=, 1 <= T <= 50000) representing the S Ize of the Matrix and the number of the instructions. The following T lines each represents an instruction have the format "Q x y" or "C x1 y1 x2 y2", which has been describe D above.
Output
For each querying output one line, which have an integer representing A[x, y].
There is a blank line between every the continuous test cases.
Sample Input
10C 2 1 2 2Q 2 2C 2 1 2 1Q 1 1C 1 1 2 1C 1 2 1 2C 1 1 2 2Q 1 1C 1 1 2 1Q 2 1
Sample Output
1001
The puzzle: This PDF is very good. On the "0" and "1" in the competition of informatics--the application of binary idea in the competition of informatics
Code:
1#include <stdio.h>2#include <string.h>3#include <math.h>4#include <algorithm>5#include <iostream>6#include <ctype.h>7#include <iomanip>8#include <queue>9#include <stdlib.h>Ten using namespacestd; One A inta[1111][1111]; - intn,m; - Chars[Ten]; the - intLowbit (intx) - { - returnX & (-x); + } - + int Get(intXinty) A { at intsum=0; - for(intI=x; I>0; i-=lowbit (i)) { - for(intJ=y; J>0; j-=Lowbit (j)) { -sum+=A[i][j]; - } - } in returnsum; - } to + voidAddintXinty) - { the for(intI=x; i<=n; i+=lowbit (i)) { * for(intJ=y; j<=n; j+=Lowbit (j)) { $a[i][j]++;Panax Notoginseng } - } the } + A intMain () the { + intT; -scanf"%d",&t); $ while(t--){ $scanf"%d%d",&n,&m); -Memset (A,0,sizeof(a)); - while(m--){ thescanf"%s", s); - if(s[0]=='C'){ Wuyi intX1,y1,x2,y2; thescanf"%d%d%d%d",&x1,&y1,&x2,&y2); -Add (x2+1, y2+1); Wu Add (x1,y1); -Add (x1,y2+1); AboutAdd (x2+1, y1); $ } - Else{ - intx, y; -scanf"%d%d",&x,&y); Aprintf"%d\n",Get(x, y)%2); + } the } - if(t) $printf"\ n"); the } the return 0; the}
Matrix (two-dimensional tree-like array)