题目链接:
http://codeforces.com/problemset/problem/341/D
题意:
给定$n \times n$的矩阵,给定$m$个操作,两种操作,一是给定子矩阵所有元素全部异或$x$,二是求给定子矩阵全部元素异或和。
数据范围:$1 \le n \le 1000, 1 \le m \le 100000, 0 \le x \le 2^{62}$
分析:
NEUOJ 1454 逃票的chanming(1
BZOJ 3132 上帝造题的七分钟
有了这两道题,再来看这道div1的D题就非常简单啦
仿佛打开了树状数组新世界的大门2333
代码:
/*************************************************************************
> File Name: 341D.cpp
> Author: jiangyuzhu
> Mail: 834138558@qq.com
> Created Time: 2016/9/27 13:47:13
************************************************************************/
using namespace std;
const int maxn = 1000 + 5;
typedef long long ll;
ll bit[2][2][maxn][maxn];
void Add(int x, int y, ll val)
{
for (int i = x; i < maxn; i += i & (-i)) {
for (int j = y; j < maxn; j += j & (-j)){
bit[x & 1][y & 1][i][j] ^= val;
}
}
}
ll Query(int x, int y)
{
ll res = 0;
for(int i = x; i; i -= i & (-i)){
for(int j = y; j; j -= j & (-j)){
res ^= bit[x & 1][y & 1][i][j];
}
}
return res;
}
int main (void)
{
int n, m;scanf("%d%d", &n, &m);
int a, b, c, d, s;
ll dt;
memset(bit, 0 ,sizeof(bit));
for(int i = 0; i < m; ++i){
scanf("%d", &s);
if(s == 2){
scanf("%d%d%d%d%I64d", &a, &b, &c, &d, &dt);
Add(a, b, dt);
Add(a, d + 1, dt);
Add(c + 1, b, dt);
Add(c + 1, d + 1, dt);
}else{
scanf("%d%d%d%d", &a, &b, &c, &d);
printf("%I64d\n", Query(c, d) ^ Query(a - 1, d) ^ Query(c, b - 1) ^ Query(a - 1, b - 1));
}
}
return 0;
}