Mobile phones_二维树状数组
【题意】给你一个矩阵(初始化为0)和一些操作,1 x y a表示在arr[x][y]加上a,2 l b r t 表示求左上角为(l,b),右下角为(r,t)的矩阵的和。
【思路】帮助更好理解树状数组。
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int N=;
int c[N][N];
int s;
int lowbit(int x)
{
return x&(-x);
}
void update(int x,int y,int a)
{
for(int i=x;i<=s;i+=lowbit(i))
{
for(int j=y;j<=s;j+=lowbit(j))
{
c[i][j]+=a;
}
}
}
int get_sum(int x,int y)
{
int sum=;
for(int i=x;i>;i-=lowbit(i))
{
for(int j=y;j>;j-=lowbit(j))
{
sum+=c[i][j];
}
}
return sum;
}
int main()
{
int ins;
int x,y,a;
int l,b,r,t;
while(scanf("%d",&ins))
{
if(ins==)
{
scanf("%d",&s);
memset(c,,sizeof(c));
}
else if(ins==)
{
scanf("%d%d%d",&x,&y,&a);
update(x+,y+,a);
}
else if(ins==)
{
scanf("%d%d%d%d",&l,&b,&r,&t);
l++,b++,t++,r++;
printf("%d\n",get_sum(r,t)+get_sum(l-,b-)-get_sum(r,b-)-get_sum(l-,t));
}
else break;
}
return ;
}
Mobile phones_二维树状数组的更多相关文章
- POJ 1195:Mobile phones 二维树状数组
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 16893 Accepted: 7789 De ...
- 【poj1195】Mobile phones(二维树状数组)
题目链接:http://poj.org/problem?id=1195 [题意] 给出一个全0的矩阵,然后一些操作 0 S:初始化矩阵,维数是S*S,值全为0,这个操作只有最开始出现一次 1 X Y ...
- poj 1195 Mobile phones(二维树状数组)
树状数组支持两种操作: Add(x, d)操作: 让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- 【POJ1195】【二维树状数组】Mobile phones
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- (简单) POJ 1195 Mobile phones,二维树状数组。
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ 1195 Mobile phones (二维树状数组)
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ 1195 Mobile phones【二维树状数组】
<题目链接> 题目大意: 一个由数字构成的大矩阵,开始是全0,能进行两种操作1) 对矩阵里的某个数加上一个整数(可正可负)2) 查询某个子矩阵里所有数字的和要求对每次查询,输出结果 解题分 ...
- POJ_1195 Mobile phones 【二维树状数组】
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013912596/article/details/33802561 题目链接:id=1195&qu ...
随机推荐
- <spring:message> 标签
可以使用<spring:message>标签结合 ResourceBundleMessageSource 的功能,在网页上显示 messages.properties 中的文字讯息,例如在 ...
- 关闭“JDK自动更新”提示
- go——beego的数据库增删改查
一直都不理解使用go语言的时候,为什么还要自己去装beego,以为使用go便可以解决所有的问题,结果在朋友的点拨下,才意识到: go与beego的关系就好比是nodejs与thinkjs的关系,因此也 ...
- C++ STL pair
没有找到priority_queue里存放pair不用typedef的方法...大概第一次觉得这个有用吧... 优先队列里和sort函数对pair 的默认排序是first从小到大,second从小到大 ...
- spring mvc如何获取问号后的url参数
@RequestMapping(method=RequestMethod.GET) public ModelAndView allUsers(@RequestParam int page){ Mode ...
- Masonry使用案列详解
案例一: 要求:无论在什么尺寸的设备上(包括横竖屏切换),红色view都居中显示.
- set常见操作:
(1)sadd 向一个集合中添加一个元素.例如:sadd set1 Hello (2)smembers 查看集合中的所有元素.例如:smembers set1 (3)srem 删除集合中一个指定的元素 ...
- Android双击返回按钮退出程序
//双击退出事件 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KE ...
- mysql中Access denied for user 'root'@'localhost' (using password:YES)(zhuan)
错误代码 1045Access denied for user 'root'@'localhost' (using password:YES) 如果你的mysql也出现以上这种提示, 建议你逐个字看完 ...
- DotNetBar v12.1.0.0 Fully Cracked
更新信息: http://www.devcomponents.com/customeronly/releasenotes.asp?p=dnbwf&v=12.1.0.0 如果遇到破解问题可以与我 ...