poj 1195 Mobile phones(二维树状数组)
来源:互联网 发布:天津网络推广公司 编辑:程序博客网 时间:2024/06/15 16:48
题目大意:
有一个大小为s的正方形矩阵,有两种操作,第一种:在(x,y)的位置增加数字a,第二种:查询左下角为(l,b),左上角为(r,t)的矩形区域内的数字和。解题思路:
二维树状数组模板题。注意点:
坐标从0开始,但线段树是从1开始,所以在处理时要给坐标加1.代码:
#include <iostream>#include <stdio.h>#include <cstring>using namespace std;int c[1050][1050];int s;int lowbit(int x){ return x&(-x);}void updata(int x,int y,int a){ while(x <= s){ int temp = y; while(temp <= s){ c[x][temp] += a; temp += lowbit(temp); } x += lowbit(x); }}int query(int x,int y){ int sum = 0; while(x > 0){ int temp = y; while(temp > 0){ sum += c[x][temp]; temp -= lowbit(temp); } x-= lowbit(x); } return sum;}int main(){ int x,y,a,l,b,r,t,comd; memset(c,0,sizeof(0)); while(true){ scanf("%d",&comd); if(comd == 0){ scanf("%d",&s); } else if(comd == 1){ scanf("%d%d%d",&x,&y,&a); updata(x+1,y+1,a); } else if(comd == 2){ scanf("%d%d%d%d",&l,&b,&r,&t); printf("%d\n",query(r+1,t+1)-query(l,t+1)-query(r+1,b)+query(l,b)); } else break; } return 0;}
0 0
- POJ 1195 Mobile phones 二维树状数组
- POJ 1195 Mobile phones【二维树状数组】
- POJ 1195 Mobile phones 二维树状数组
- poj 1195 Mobile phones 二维树状数组
- POJ 1195 Mobile phones 二维树状数组
- poj 1195 Mobile phones +二维树状数组
- POJ 1195 Mobile phones 二维树状数组
- Mobile Phones poj 1195--二维树状数组
- POJ 1195 Mobile phones【二维树状数组】
- POJ 1195 Mobile phones(二维树状数组)
- POJ 1195 Mobile phones(二维树状数组)
- POJ 1195 Mobile phones(二维树状数组)
- poj 1195 mobile phones 二维树状数组
- POJ 1195 Mobile phones 二维树状数组
- Poj 1195 Mobile phones 二维树状数组
- poj 1195 Mobile phones(二维树状数组)
- poj 1195 Mobile phones 二维树状数组
- POJ 1195 Mobile phones (二维树状数组)
- PAT乙级1008: 数组元素循环右移问题 (20)
- 指针和引用的差别
- java (String)强转 和 toString() 的区别
- apache.commons.lang 包 StringUtils 的 isBank() 方法认知
- 关于Android开发中的证书和密钥等问题
- poj 1195 Mobile phones(二维树状数组)
- shell原理和问答机制引入
- cf#221-div1-D - Tree and Queries-dfs序+莫队算法
- 简易版 文件上传UpdateFile(Struts2版)
- HBase Rowkey的散列与预分区设计
- 2016年武汉科技大学邀请赛网络赛 F题
- QTableWidget使用总结
- db2 常用sql
- <html>img、map、area