标签:
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 673 Accepted Submission(s): 223
int sum(int x,int y){ int ret=0; for(int i=x;i>0;i-=lowbit(i)){ for(int j=y;j>0;j-=lowbit(j)){ ret+=C[i][j]; } } return ret; }
修改:
void modify(int x,int y,int val){ for(int i=x;i<=n;i+=lowbit(i)){ for(int j=y;j<=m;j+=lowbit(j)){ C[i][j] += val; } } }
#include<bits/stdc++.h> using namespace std; typedef long long INT; const int maxn=550; int a[maxn][maxn]; int C[maxn][maxn]; int n,m; int lowbit(int x){ return x & (-x); } void modify(int x,int y,int val){ for(int i=x;i<=n;i+=lowbit(i)){ for(int j=y;j<=m;j+=lowbit(j)){ C[i][j] ^= val; } } } int sum(int x,int y){ int ret=0; for(int i=x;i>0;i-=lowbit(i)){ for(int j=y;j>0;j-=lowbit(j)){ ret ^=C[i][j]; } } return ret; } int main(){ int t,q; scanf("%d",&t); while(t--){ memset(a,0,sizeof(a)); memset(C,0,sizeof(C)); scanf("%d%d%d",&n,&m,&q); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ scanf("%d",&a[i][j]); } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ modify(i,j,a[i][j]); } } int typ,x1,x2,y1,y2,c; for(int i=0;i<q;i++){ scanf("%d",&typ); if(typ==1){ scanf("%d%d%d%d",&x1,&y1,&x2,&y2); int ans1,ans2,ans3,ans4; ans1=sum(x2,y2); ans2=sum(x2,y1-1); ans3=sum(x1-1,y2); ans4=sum(x1-1,y1-1); int ans=ans1^ans2^ans3^ans4; printf("%s\n",ans==0?"No":"Yes"); }else{ scanf("%d%d%d",&x1,&y1,&c); modify(x1,y1,c^a[x1][y1]); a[x1][y1]=c; } } } return 0; }
HDU 5465——Clarke and puzzle——————【树状数组BIT维护前缀和+Nim博弈】
标签:
原文地址:http://www.cnblogs.com/chengsheng/p/4832894.html