标签:str ble NPU lin ati clu row type 前缀和
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 2614 Accepted Submission(s): 1314
题意:
1.把空间上以(x1,y1,z1),(x2,y2,z2)为端点的区域所有的1变成0,0变成1.
2.求出(1,1,1)->(x,y,z)的区域的值.
转化一下思想,成为前缀和,然后&1,就知道当前位置是1还是0了.
详见代码.
1 #include <iostream> 2 #include <cstring> 3 #define N 105 4 using namespace std; 5 6 int sum[N][N][N]; 7 8 int lowbit(int x){ return x&(-x); } 9 10 void update(int a,int b,int c){ 11 for(int i = a;i<=N;i+=lowbit(i)){ 12 for(int j = b;j<=N;j+=lowbit(j)){ 13 for(int k = c; k<=N; k += lowbit(k)){ 14 sum[i][j][k]++; 15 } 16 } 17 } 18 } 19 20 int query(int a,int b,int c){ 21 int ans = 0; 22 for(int i = a;i>0;i-=lowbit(i)){ 23 for(int j = b;j>0;j-=lowbit(j)){ 24 for(int k = c;k>0;k-=lowbit(k)){ 25 ans += sum[i][j][k]; 26 } 27 } 28 } 29 return ans; 30 } 31 32 int main(){ 33 int n,m; 34 while(cin>>n>>m){ 35 memset(sum,0,sizeof(sum)); 36 int p,x,y,z,x1,y1,z1; 37 while(m--){ 38 cin>>p; 39 if(p){ 40 cin>>x>>y>>z>>x1>>y1>>z1; 41 update(x,y,z); 42 update(x,y,z1+1); 43 update(x,y1+1,z); 44 update(x1+1,y,z); 45 update(x1+1,y1+1,z); 46 update(x1+1,y,z1+1); 47 update(x,y1+1,z1+1); 48 update(x1+1,y1+1,z1+1); 49 }else{ 50 cin>>x>>y>>z; 51 cout<<(query(x,y,z)&1)<<endl; 52 } 53 } 54 } 55 return 0; 56 }
标签:str ble NPU lin ati clu row type 前缀和
原文地址:https://www.cnblogs.com/zllwxm123/p/9343765.html