Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
二维树状数组 贡献了一次wa 但还是水过了#include<stdio.h> int d[1025][1025]; int n; int lowbit(int i) { return i&(i*(-1)); } void add(int i,int j,int w) { int mj=j; while(i<=n) { for(j=mj;j<=n;j+=lowbit(j)) { d[i][j]+=w; // j+=lowbit(j); } i+=lowbit(i); } } int sum(int i,int j) { int mj=j; int s=0; while(i>0) { for(j=mj;j>0;j-=lowbit(j)) s+=d[i][j]; i-=lowbit(i); } return s; } int main (void) { int m; int ins; int a,b,c; int r; scanf("%d %d",&m,&n); while(scanf("%d",&ins),ins!=3) { if(ins==1) { scanf("%d %d %d",&a,&b,&c); add(a+1,b+1,c); } else if(ins==2) { scanf("%d %d %d %d",&a,&b,&c,&r); printf("%d\n",sum(c+1,r+1)+sum(a,b)-sum(c+1,b)-sum(a,r+1)); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator