hdu 3584 Cube
题意:
给出一个N * N * N规模的矩阵,有2种操作:
1.把A[i, j, k]反转,(x1<=i<=x2,y1<=j<=y2,z1<=k<=z2).
2.查询A[x,y,z]的值。
思路:
三维树状数组裸题,得画图好好推导一下。
区间更新,单点查询。
代码:
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int N = 105; int c[N][N][N]; int n; int lowbit(int x) { return x&(-x); } void add(int x,int y,int z) { for (int i = x;i <= n;i += lowbit(i)) { for (int j = y;j <= n;j += lowbit(j)) { for (int k = z;k <= n;k += lowbit(k)) { c[i][j][k]++; } } } } int getsum(int x,int y,int z) { int ans = 0; for (int i = x;i > 0; i-= lowbit(i)) { for (int j = y;j > 0;j -= lowbit(j)) { for (int k = z;k > 0;k -= lowbit(k)) { ans += c[i][j][k]; } } } return ans; } int main() { int m; while (scanf("%d%d",&n,&m) != EOF) { memset(c,0,sizeof(c)); while (m--) { int op; scanf("%d",&op); if (op == 1) { int x1,y1,z1; int x2,y2,z2; scanf("%d%d%d",&x1,&y1,&z1); scanf("%d%d%d",&x2,&y2,&z2); add(x1,y1,z1); add(x1,y2+1,z1); add(x2+1,y1,z1); add(x1,y1,z2+1); add(x2+1,y2+1,z1); add(x2+1,y1,z2+1); add(x1,y2+1,z2+1); add(x2+1,y2+1,z2+1); } else { int x,y,z; scanf("%d%d%d",&x,&y,&z); int ans = getsum(x,y,z); if (ans & 1) puts("1"); else puts("0"); } } } return 0; }
康复训练中~欢迎交流!