Matrix

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;
}

matrix calculus

2010年02月16日 46KB 下载

Android画图之Matrix剖析

2011年08月04日 66KB 下载

Matrix Algebra Useful for Statistics,2ed,2017 ed

2018年04月20日 14.32MB 下载

C++ 矩阵简单的计算器

2012年05月12日 8KB 下载

步入Matrix函数 步入Matrix函数 步入Matrix函数

2011年08月01日 34KB 下载

Matrix Calculation

2011年01月21日 199KB 下载

05-03 5483

04-06 2853

11-07 1511

05-18 590