poj 1195 二维树状数组
来源:互联网 发布:知乎炸鱼 编辑:程序博客网 时间:2024/04/25 14:39
裸的二维树状数组模板题
求和公式注意了。
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<cmath>#include<algorithm>#include<set>#include<map>#include<stack>#include<queue>#include<vector>using namespace std;int n;int c[1111][1111];int a[1111][1111];#pragma comment(lingker,"/STACK:36777216") //hdu外挂//输入优化inline void RD(int &ret){ char c; do { c=getchar(); }while(c<'0'||c>'9'); ret=c-'0'; while((c=getchar())>='0'&&c<='9') ret=ret*10+(c-'0');}//输出优化inline void OT(int a){ if(a>=10) OT(a/10); putchar(a%10+'0');}int lowbit(int x){ return x&(-x);}void add(int i,int j,int detal){ int x,y; for(x=i;x<=n;x+=lowbit(x)) { for(y=j;y<=n;y+=lowbit(y)) { c[x][y]+=detal; } }}int sum(int i,int j){ int x,y; int ans=0; for(x=i;x>0;x-=lowbit(x)) { for(y=j;y>0;y-=lowbit(y)) { ans+=c[x][y]; } } return ans;}int main(){ int f,x1,y1,x2,y2,num; while(scanf("%d",&f)) { if(f==3) break; if(f==0) scanf("%d",&n); if(f==1) { scanf("%d%d%d",&x1,&y1,&num); // cin>>x1>>y1>>num; x1++; y1++; add(x1,y1,num); } if(f==2) { scanf("%d%d%d%d",&x1,&y1,&x2,&y2); // cin>>x1>>y1>>x2>>y2; x1++; y1++; x2++; y2++; //求和注意 printf("%d\n",sum(x2,y2)+sum(x1-1,y1-1)-sum(x2,y1-1)-sum(x1-1,y2)); //cout<<sum(x2,y2)-sum(x1,y1)<<endl; } } return 0;}
- poj 2155 二维树状数组 poj 1195 二维树状数组
- POJ 1195 二维树状数组
- POJ 1195 二维树状数组
- POJ 1195 二维树状数组
- Poj 1195 二维树状数组
- POJ 1195 二维树状数组
- 【二维树状数组】POJ 1195
- POJ 1195 二维树状数组
- poj 1195 二维树状数组
- POJ 1195 二维树状数组
- POJ 1195 二维树状数组
- POJ 1195 二维树状数组
- POJ-1195-二维树状数组
- poj 1195 二维树状数组 及二维树状数组模板
- POJ 2352 Stars 树状数组 与 1195二维树状数组
- POJ 1195 Mobile phones 二维树状数组
- POJ 1195 Mobile phones【二维树状数组】
- POJ 1195 Mobile phones 二维树状数组
- win 7 修复 mbr
- C#中将查询的结果集使用json序列化并传输后反序列化
- 统计学习方法第四章,贝叶斯估计的实现
- 如何评估个人的软件开发能力
- 如何彻底的删除Oracle表
- poj 1195 二维树状数组
- 谁在使用我的网站——用户忠诚和价值分析
- Tab控制器 ( UITabBarController )
- 数据库相关
- JDK环境变量设置详解
- Eclipse中调用VS 2012生成的DLL文件,进行调试的步骤。。。[含VS2012中release版本的调试配置]
- Linux2.6内核--内存管理(1)--分页机制
- shell字符串操作之cut---实现字符串截取
- cocos2d-x锚点问题