题目链接:

https://vjudge.net/problem/POJ-2155

题目大意:

给一个n*n的01矩阵,然后有两种操作(m次)C x1 y1 x2 y2是把这个小矩形内所有数字异或一遍,Q x y 是询问当前这个点的值是多少?n<=1000 m<=50000.

解题思路:

裸的二维树状数组,但是这里是区域更新,单点查询,

做法应该是

POJ-2155 Matrix---二维树状数组+区域更新单点查询-LMLPHP

  #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<list>
#include<deque>
#include<sstream>
#include<cctype>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, s, t) for(int i = (s); i < (t); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e3 + ;
const double eps = 1e-;
const int INF = << ;
const int dir[][] = {,,,,,-,-,};
const double pi = 3.1415926535898;
int T, n, m, cases;
int tree[maxn][maxn];
int lowbit(int x)
{
return x&(-x);
}
int sum(int x, int y)
{
int ret = ;
for(int i = x; i <= n; i += lowbit(i))
{
for(int j = y; j <= n; j += lowbit(j))
ret += tree[i][j];
}
return ret;
}
void add(int x, int y, int d)
{
for(int i = x; i > ; i -= lowbit(i))
{
for(int j = y; j > ; j -= lowbit(j))
tree[i][j] += d;
}
}
int main()
{
std::ios::sync_with_stdio(false);
cin >> T;
while(T--)
{
cin >> n >> m;
string c;
int x1, y1, x2, y2;
memset(tree, , sizeof(tree));
while(m--)
{
cin >> c;
if(c[] == 'C')
{
cin >> x1 >> y1 >> x2 >> y2;
add(x2, y2, );
add(x1 - , y1 - , );
add(x2, y1 - , -);
add(x1 - , y2, -);
}
else if(c[] == 'Q')
{
cin >> x1 >> x2;
cout<<(sum(x1, x2)&)<<endl;
}
}
if(T)cout<<endl;
}
return ;
}
05-07 15:17