Clarke and puzzle
Accepts: 129
Submissions: 322
Time Limit: 4000/2000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 500 + 5
int n, m, q;
int c[N][N];
int sum[N][N];
inline int lowbit(int x)
{
return x & (-x);
}
void update(int x, int y, int data)
{
for(int i = x; i <= n; i += lowbit(i))
for(int j = y; j <= m; j += lowbit(j))
sum[i][j] ^= data;
}
int get_sum(int x, int y)
{
int res = 0;
for(int i = x; i > 0; i -= lowbit(i))
for(int j = y; j > 0; j -= lowbit(j))
res ^= sum[i][j];
return res;
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
memset(sum, 0, sizeof sum);
scanf("%d%d%d", &n, &m, &q);
for(int i = 1; i <= n ; i++)
for(int j = 1; j <= m; j++)
{
scanf("%d", &c[i][j]);
update(i, j, c[i][j]);
}
int x1, x2, y1, y2, op;
while(q--)
{
scanf("%d", &op);
if(op == 1)
{
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
int ans = 0;
ans = get_sum(x2, y2) ^ get_sum(x1 - 1, y1 - 1) ^ get_sum(x2, y1 - 1) ^ get_sum(x1 - 1, y2);
(ans == 0) ? printf("No\n") : printf("Yes\n");
}
else
{
scanf("%d%d%d", &x1, &y1, &x2);
update(x1, y1, c[x1][y1] ^ x2);
c[x1][y1] = x2;
}
}
}
return 0;
}
/*
1
3 3 10
1 1 1
1 1 1
1 1 1
*/