本文共 1047 字,大约阅读时间需要 3 分钟。
#include #include #include #include #include #include #include #include #include #include #include #include using namespace std;const int MAX=1200;int c[MAX][MAX];int n;int LowBit(int t){ return t&(-t);}int Sum(int endx,int endy)//(1,1) 到 (endx,endy) 矩阵的和{ int sum=0; int temp=endy; while(endx>0) { endy=temp; while (endy>0) { sum+=c[endx][endy]; endy-=LowBit(endy); } endx-=LowBit(endx); } return sum;}void add(int addx,int addy,int num)//(x,y) 处增加num{ int temp=addy; while (addx <=n) { addy=temp; while(addy<=n) { c[addx][addy]+=num; addy+=LowBit(addy); } addx+=LowBit(addx); }}int GetSum(int l,int b,int r,int t)//求 (l,b) (r,t) 矩阵的和{ return Sum(r,t)-Sum(r,b-1)-Sum(l-1,t)+Sum(l-1,b-1);}int main(){ int gg; int x; int a1,a2,a3,a4; scanf("%d",&n); while(scanf("%d",&x)!=EOF&&x!=3){ if(x==1){ scanf("%d%d%d",&a1,&a2,&a3); add(a1+1,a2+1,a3); } else{ scanf("%d%d%d%d",&a1,&a2,&a3,&a4); cout< <
转载于:https://www.cnblogs.com/yigexigua/p/4162652.html