poj1195 mobile phones 【二维树状数组】
来源:互联网 发布:网络精灵pipopa 编辑:程序博客网 时间:2024/05/19 16:33
一次AC
二维树状数组,有模版很好办
注意二维树状数组这个下标是[1][1]的
#include <cstdio>#include <cstdlib>#include <iostream>#include <algorithm>#include <cstring>#include <cmath>using namespace std;const int Max = 1030;int row, col, ar[Max][Max];// 二维的其实下标为[1][1],这个要记得。int lowbit(int x){ return x & (-x);}void add(int i, int j, int w){ int tmpj; while(i <= row){ tmpj = j; while(tmpj <= col){ ar[i][tmpj] += w; tmpj += lowbit(tmpj); } i += lowbit(i); }}int sum(int i, int j){ int tmpj, ans = 0; while(i > 0){ tmpj = j; while(tmpj > 0){ ans += ar[i][tmpj]; tmpj -= lowbit(tmpj); } i -= lowbit(i); } return ans;}int main(){#ifndef ONLINE_JUDGEfreopen("G:/1.txt","r",stdin);freopen("G:/2.txt","w",stdout);#endifint tmp,n;scanf("%d%d",&tmp,&n);row=col=n;while(true){int kind,x,y,xx,yy,v;scanf("%d",&kind);if(kind==1){scanf("%d%d%d",&x,&y,&v);add(x+1,y+1,v);}else if(kind==2){scanf("%d%d%d%d",&x,&y,&xx,&yy);x++;y++;xx++;yy++;printf("%d\n",sum(xx,yy)-sum(xx,y-1)-sum(x-1,yy)+sum(x-1,y-1));}else{break;}}return 0;}
0 0
- POJ1195 Mobile phones, 二维树状数组
- poj1195 Mobile phones 二维树状数组
- POJ1195--Mobile phones--二维树状数组
- poj1195 mobile phones 【二维树状数组】
- POJ1195 Mobile phones 【二维树状数组】
- poj1195--Mobile phones(二维树状数组)
- poj1195 Mobile phones 二维树状数组
- POJ1195 Mobile phones【树状数组】【二维】
- POJ1195:Mobile phones(二维树状数组)
- POJ1195 Mobile phones 二维树状数组
- (POJ1195)Mobile phones <二维树状数组>
- poj1195 Mobile phones(二维树状数组)
- poj1195~Mobile phones(二维树状数组)
- poj1195 Mobile phones(二维树状数组)
- POJ1195 Mobile phones(树状数组)
- [树状数组] poj1195 Mobile phones
- POJ1195 Mobile phones 二维树状数组 更新节点,查询区域
- POJ1195 Mobile phones(简单二维树状数组)
- 如何利用 release 版本的 backtrace 来定位 android NDK 程序的崩溃位置
- 【Windows socket+IP+UDP+TCP】网络基础
- 《大话设计模式》—— 读后感(24)加薪非要老总批?——职责链模式
- 在线编辑器Kindedior在ASP.NET下实现图片批量上传
- CocoaPods的install和update卡在“Anylyzing dependencies”的问题解决方案[效率]
- poj1195 mobile phones 【二维树状数组】
- mysql处理海量数据时的一些优化查询速度方法
- Web基础架构:负载均衡和LVS
- [SSH]整合:当提示插入数据提示Null pointer (配置问题)
- 十天已过
- hadoop cdh安装
- ARM9外部中断裸机实验
- 触屏事件(单点触屏)
- 在ios项目中使用常量的最佳实践