题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=3584
题目大意:
给定一个N*N*N多维数据集A,其元素是0或是1。A[i,j,k]表示集合中第
i 行,第 j 列与第 k 层的值。
首先由A[i,j,k] = 0(1 <= i,j,k <= N)。
给定两个操作:
1:改变A[i,j,k]为!A[i,j,k]。
2:查询A[i,j,k]的值。
解题思路:
三维树状数组模拟,利用容斥原理
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 #include<string> 6 #include<cmath> 7 #include<set> 8 #include<queue> 9 #include<map> 10 #include<stack> 11 #include<vector> 12 #include<list> 13 #include<deque> 14 #include<sstream> 15 #include<cctype> 16 #define REP(i, n) for(int i = 0; i < (n); i++) 17 #define FOR(i, s, t) for(int i = (s); i < (t); i++) 18 #define MEM(a, x) memset(a, x, sizeof(a)); 19 using namespace std; 20 typedef long long ll; 21 typedef unsigned long long ull; 22 const int maxn = 105; 23 const double eps = 1e-10; 24 const int INF = 1 << 30; 25 const int dir[4][2] = {1,0,0,1,0,-1,-1,0}; 26 const double pi = 3.1415926535898; 27 int T, n, m, cases; 28 int tree[maxn][maxn][maxn]; 29 int a[maxn][maxn][maxn]; 30 int lowbit(int x) 31 { 32 return x&(-x); 33 } 34 int sum(int x, int y, int z) 35 { 36 int ans = 0; 37 for(int i = x; i <= n; i += lowbit(i)) 38 for(int j = y; j <= n; j += lowbit(j)) 39 for(int k = z; k <= n; k += lowbit(k)) 40 ans += tree[i][j][k]; 41 return ans; 42 } 43 void add(int x, int y, int z, int d) 44 { 45 for(int i = x; i > 0; i -= lowbit(i)) 46 for(int j = y; j > 0; j -= lowbit(j)) 47 for(int k = z; k > 0; k -= lowbit(k)) 48 tree[i][j][k] += d; 49 } 50 int main() 51 { 52 while(cin >> n >> m) 53 { 54 MEM(tree, 0); 55 MEM(a, 0); 56 int t, x1, y1, z1, x2, y2, z2; 57 while(m--) 58 { 59 scanf("%d", &t); 60 if(t) 61 { 62 scanf("%d%d%d%d%d%d", &x1, &y1, &z1, &x2, &y2, &z2); 63 add(x2, y2, z2, 1); 64 add(x2, y1 - 1, z2, 1); 65 add(x1 - 1, y2, z2, 1); 66 add(x2, y2, z1 - 1, 1); 67 add(x1 - 1, y1 - 1, z2, 1); 68 add(x1 - 1, y2, z1 - 1, 1); 69 add(x2, y1 - 1, z1 - 1, 1); 70 add(x1 - 1, y1 - 1, z1 - 1, 1); 71 } 72 else 73 { 74 scanf("%d%d%d", &x1, &y1, &z1); 75 cout<<(sum(x1, y1, z1)&1)<<endl; 76 } 77 } 78 } 79 return 0; 80 }
原文地址:https://www.cnblogs.com/fzl194/p/8955263.html
时间: 2024-11-08 21:56:09