# Matrix

191人阅读 评论(0)

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 (if it is a '0' then change it into '1' otherwise change it into '0'). To maintain 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].

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <cmath>
#include <cctype>
#include <cfloat>
#include <climits>
#include <complex>
#include <deque>
#include <list>
#include <set>
#include <utility>
#define rt return
#define fr freopen("in.txt","r",stdin)
#define fw freopen("out.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define detie ios_base::sync_with_stdio(false);cin.tie(false);cout.tie(false)
#define pii pair<int,int>
#define lowbit(x) x&(-x)
using namespace std;
#define maxi 0x3f3f3f3f
#define MAX 1005

int bit[MAX][MAX];
int X;
int N, T;

void add(int x, int y, int a)
{
for (int i = x; i <= N; i += lowbit(i))
{
for (int j = y; j <= N; j += lowbit(j))
{
bit[i][j] += a;
}
}
}

int sum(int x, int y)
{
int ans = 0;
for (int i = x; i >0; i -= lowbit(i))
{
for (int j = y; j >0; j -= lowbit(j))
{
ans += bit[i][j];
}
}
rt ans;
}

int main()
{
//fr;
detie;
scanf("%d", &X);
while (X--)
{

char c[10];
int x1, x2, y1, y2;
memset(bit, 0, sizeof bit);
scanf("%d %d", &N, &T);
while (T--)
{
scanf("%s", c);
if (c[0]=='C')
{
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
add(x2 + 1, y2 + 1, 1);
}
else
{
scanf("%d %d", &x1, &y1);
printf("%d\n", sum(x1, y1)&1);
}
}
printf("\n");
}
rt 0;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：3788次
• 积分：597
• 等级：
• 排名：千里之外
• 原创：59篇
• 转载：0篇
• 译文：0篇
• 评论：0条
友情链接
评论排行