POJ2155 Matrix <树套树/二维树状数组>
Problem
Matrix
Time Limit:
Memory Limit:
Description
Given an matrix , whose elements are either or . means the number in the row and column. Initially we have .
We can change the matrix in the following way. Given a rectangle whose upper-left corner is and lower-right corner is , we change all the elements in the rectangle by using “not” operation (if it is a ‘’ then change it into ‘’ otherwise change it into ‘’). To maintain the information of the matrix, you are asked to write a program to receive and execute two kinds of instructions.
- () changes the matrix by using the rectangle whose upper-left corner is and lower-right corner is .
- () querys .
Input
The first line of the input is an integer $X (X \le 10) $representing the number of test cases. The following X blocks each represents a test case.
The first line of each block contains two numbers and (, ) representing the size of the matrix and the number of the instructions. The following lines each represents an instruction having the format “ ” or “ ”, which has been described above.
Output
For each querying output one line, which has an integer representing .
There is a blank line between every two continuous test cases.
Sample Input
1 | 1 |
Sample Output
1 | 1 |
标签:线段树套线段树
/二维树状数组
Solution
此题最简单的方法是二维树状数组,但因为二维树状数组没太大用,所以练习线段树的树套树。
此题用作树套树的模板题再合适不过。
Code
1 |
|