poj 1195(树状数组)
来源:互联网 发布:北京网络监控安装 编辑:程序博客网 时间:2024/05/18 13:27
点击打开链接
题意:
给你一个n*n的矩阵进行操作,
1 x, y, a, -将右下角的矩阵+a;
2 x,y,xx,yy 求(x,y)和(xx,yy)构成的矩阵的和。。。
将sum和add都换为而二维的就行了。。
#include"stdio.h"#include"string.h"#include"algorithm"using namespace std;#define N 1025int A[N][N];int n;int bit(int x){return x&(-x);}int sum(int x,int y){int ans=0;for(int i=x;i>0;i-=bit(i)){for(int j=y;j>0;j-=bit(j))ans+=A[i][j];}return ans;}void add(int x,int y,int a){for(int i=x;i<=n;i+=bit(i)){for(int j=y;j<=n;j+=bit(j))A[i][j]+=a;}}int main(){int i,t;int x,y,xx,yy;while(scanf("%d",&t)!=-1){if(t==0){scanf("%d",&n);memset(A,0,sizeof(A));}if(t==1){scanf("%d%d%d",&x,&y,&i);x++;y++;add(x,y,i);}if(t==2){scanf("%d%d%d%d",&x,&y,&xx,&yy);x++;y++;xx++;yy++;printf("%d\n",sum(xx,yy)+sum(x-1,y-1)-sum(x-1,yy)-sum(xx,y-1));}if(t==3)break;}return 0;}
- poj 1195(树状数组)
- 树状数组(poj 1195,poj 3321)
- 树状数组 poj 1195
- poj 1195(树状数组)
- poj 1195 树状数组
- poj 1195 Mobile phones(树状数组)
- poj - 1195 - Mobile phones(树状数组)
- POJ 1195 Mobile phones(树状数组)
- poj 1195(二维树状数组)
- poj 1195(二维树状数组)
- 二维树状数组(poj 1195)
- POJ 1195 Mobile phones(树状数组)
- poj 1195 Mobile phones(树状数组)
- poj 2155 二维树状数组 poj 1195 二维树状数组
- POJ 1195 二维树状数组
- POJ 1195 二维树状数组
- POJ 1195 二维树状数组
- Poj 1195 二维树状数组
- Thinking in Java [Java编程机制] 学习笔记 -- List / ArrayList
- linux下 nm 命令
- @property的属性参数
- StringUtils.equals() 用法
- 1396 - Most Distant Point from the Sea
- poj 1195(树状数组)
- strcpy(),memcpy(),memmove(),memset(),strcmp(),strstr()的实现
- PJSIP2.0使用以及交叉编译存在问题解决
- HDOJ 1076 An Easy Task
- JAVA设计模式——单例模式
- volatile关键字的作用
- libx264、ffmpeg、SDL交叉编译
- NYOJ,32,组合数
- SQLServer中的查询