膜拜: https://www.cnblogs.com/clnchanpin/p/7135784.html
Cube
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 2939 Accepted Submission(s): 1472
Problem Description
Given an N*N*N cube A, whose elements are either 0 or 1. A[i, j, k] means the number in the i-th row , j-th column and k-th layer. Initially we have A[i, j, k] = 0 (1 <= i, j, k <= N).
We define two operations, 1: “Not” operation that we change the A[i, j, k]=!A[i, j, k]. that means we change A[i, j, k] from 0->1,or 1->0. (x1<=i<=x2,y1<=j<=y2,z1<=k<=z2).
0: “Query” operation we want to get the value of A[i, j, k].
Input
Multi-cases.
First line contains N and M, M lines follow indicating the operation below.
Each operation contains an X, the type of operation. 1: “Not” operation and 0: “Query” operation.
If X is 1, following x1, y1, z1, x2, y2, z2.
If X is 0, following x, y, z.
Output
For each query output A[x, y, z] in one line. (1<=n<=100 sum of m <=10000)
Sample Input
2 5
1 1 1 1 1 1 1
0 1 1 1
1 1 1 1 2 2 2
0 1 1 1
0 2 2 2
Sample Output
1 0 1
Author
alpc32
Source
2010 ACM-ICPC Multi-University Training Contest(15)——Host by NUDT
Recommend
zhouzeyong | We have carefully selected several similar problems for you: 3450 1892 3743 2852 2227
题意 :大家都应该明白,就是一个三维的树状数组。但是,我操了,这个边界值,思维不好我估计咱们的脑壳就炸了。
我也没办法画出来,但是我做完想到了一个方法,三维,六个面,那么把六个面都画出来,取边界值就ok了。
前、后、左、右、上、下(当然如果思维能力很强就无所谓了)
实在不行就找个A4纸,画一个大一点的正方体,取两个点,画一画就出来了。
反正算法没啥难的吗,就是这个边界。。。。。
如果想到什么方法还会更新《未完待续。。。》期待大佬有好的方法清晰地找出。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<algorithm>
#define sc(x) scanf("%d",&x)
#define scc(x,y) scanf("%d%d",&x,&y)
#define scll(x) scanf("%lld",&x)
#define mem(x) memset(x,0,sizeof x)
#define ll long long
using namespace std;
const int maxn = 105;
int c[maxn][maxn][maxn];
int N,M;
int lowbit(int x){
return x & -x;
}
void update(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]+=1;
}
}
}
}
int query(int x,int y,int z){
int total=0;
for(int i=x;i;i-=lowbit(i)){
for(int j=y;j;j-=lowbit(j)){
for(int k=z;k;k-=lowbit(k)){
total+=c[i][j][k];
}
}
}
return total & 1;
}
int main(){
while(scc(N,M)!=EOF){
mem(c);
for(int i=1;i<=M;i++){
int op;
sc(op);
if(op==1){
int x1,y1,z1,x2,y2,z2;
scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
update(x2+1,y2+1,z2+1);
update(x2+1,y2+1,z1);
update(x2+1,y1,z2+1);
update(x1,y2+1,z2+1);
update(x1,y1,z2+1);
update(x1,y2+1,z1);
update(x2+1,y1,z1);
update(x1,y1,z1);
}
if(op==0){
int x1,y1,z1;
scanf("%d%d%d",&x1,&y1,&z1);
cout<<query(x1,y1,z1)<<endl;
}
}
}
}