联想2155:PKU 2155来源: 发布时间:星期一, 2009年11月30日 浏览:0次 评论:0
/*
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5565 Accepted: 2047 Description Given an N*N matrix A, whose elements are 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 way. Given a rectangle whose upper-left corner is (x1, y1) and lower-right corner is (x2, y2), we change all the elements in the rectangle by using "not" operation ( it is a '0' then change it o '1' otherwise change it o '0'). To tain the information of the matrix, you are asked to write a program to receive and execute two kinds of instructions. 1. C x1 y1 x2 y2 (1 <= x1 <= x2 <= n, 1 <= y1 <= y2 <= n) changes the matrix by using the rectangle whose upper-left corner is (x1, y1) and lower-right corner is (x2, y2). 2. Q x y (1 <= x, y <= n) querys A[x, y]. Input The first line of the input is an eger X (X <= 10) representing the number of test s. The following X blocks each represents a test . The first line of each block contains two numbers N and T (2 <= N <= 1000, 1 <= T <= 50000) representing the size of the matrix and the number of the instructions. The following T lines each represents an instruction having the format "Q x y" or "C x1 y1 x2 y2", which has been described above. Output For each querying output _disibledevent=> { for (j = y; j <= N; j lowbit(j)) { c[i][j] delta; } } } sum( x, y) { res = 0, i, j; for (i = x; i > 0; i -= lowbit(i)) { for (j = y; j > 0; j -= lowbit(j)) { res c[i][j]; } } res; } { t, rec; scanf("%d", &t); rec = t; while (t--) { (t != rec - 1) { putchar('\n'); } cmd; mem(c, 0, (c)); scanf("%d %d", &N, &cmd); while (cmd--) { char optr[10]; scanf("%s", optr); (optr[0] 'C') { x1, y1, x2, y2; scanf("%d %d %d %d", &x1, &y1, &x2, &y2); mody(x1, y1, 1); mody(x2 + 1, y2 + 1, 1); mody(x1, y2 + 1, 1); mody(x2 + 1, y1, 1); } { x, y; scanf("%d %d", &x, &y); prf("%d\n", sum(x, y) % 2); } } } 0; } 0
相关文章读者评论发表评论 |