POJ_1195 Mobile phones 【二维树状数组】
题目链接: id=1195" rel="nofollow">http://poj.org/problem?id=1195
纯纯的二维树状数组,不解释。仅仅须要注意一点,由于题目中的数组从0開始计算。所以维护的时候须要加1。由于树状数组的下标是不能为1的
代码:
#include <iostream>
#include <cstdio>
#define N 1030
using namespace std;
int c[N][N];
int cas,n,x,y,a,l,b,r,t;
int Lowbit(int x)
{
return x & (-x);
}
void Updata(int x,int y,int a)
{
int i,k;
for(i=x; i<=n; i+=Lowbit(i))
for(k=y; k<=n; k+=Lowbit(k))
c[i][k]+=a;
}
int Getsum(int x,int y)
{
int i,k,sum = 0;
for(i=x; i>0; i-=Lowbit(i))
for(k=y; k>0; k-=Lowbit(k))
sum += c[i][k];
return sum;
}
int main()
{
scanf("%d%d",&cas,&n);
while(~scanf("%d",&cas))
{
if(cas==1)
{
scanf("%d%d%d",&x,&y,&a);
Updata(x+1,y+1,a);
}
if(cas==2)
{
scanf("%d%d%d%d",&l,&b,&r,&t);
int a=Getsum(r+1,t+1)-Getsum(l,t+1)-Getsum(r+1,b)+Getsum(l,b);
printf("%d\n",a);
}
if(cas==3)
return 0;
}
return 0;
}
POJ_1195 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]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...
- Mobile phones_二维树状数组
[题意]给你一个矩阵(初始化为0)和一些操作,1 x y a表示在arr[x][y]加上a,2 l b r t 表示求左上角为(l,b),右下角为(r,t)的矩阵的和. [思路]帮助更好理解树状数组. ...
- poj1195Mobile phones(二维树状数组)
http://poj.org/problem?id=1195 模版题 i写成k了 找了一个多小时没找出来.. #include <iostream> #include<cstring ...
- poj_1195Mobile phones,二维树状数组
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...
- 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 ...
随机推荐
- Powershell对象条件查询筛选
在 Windows PowerShell 中,与所需的对象数量相比,通常生成的对象数量以及要传递给管道的对象数量要多得多.可以使用 Format cmdlet 来指定要显示的特定对象的属性,但这并不能 ...
- Compiler Error C2872: ambiguous symbol
参考资料:http://blog.csdn.net/greytree/article/details/354530 刚才写的程序报错ERROR C2872(CL.exe)原因很简单 ZThread有定 ...
- asp.net出现的异常:"由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值" 的解决方法
引用: https://support.microsoft.com/zh-cn/kb/312629 症状 如果您使用的Response.End. Response.Redirect或Server.Tr ...
- vim 设置
TL;DR: $ git clone https://github.com/sontek/dotfiles.git $ cd dotfiles $ ./install.sh vim Download ...
- Mybatis热加载Mapper.xml
开发的时候,写Mybatis Mapper.xml文件的时候,每次修改SQL都需要重启服务,感觉十分麻烦,于是尝试写了一个Mybatis的Mapper.xml热加载. 能在修改Mapper.xml之后 ...
- pipe_wait问题_转
转自:调用Process.waitfor导致的进程挂起 最近遇到pipe_wait问题,父进程调用子进程时,子进程阻塞,cat /proc/$child/wchan输出pipe_wait,进程阻塞在p ...
- ubuntu12.10更新源
ubuntu12.10更新源 2013-03-10 20:48:17| 分类: Linux |字号 订阅 不同的网络状况连接以下源的速度不同, 建议在添加前手动验证以下源的连接速度(ping下就 ...
- JDK7 Garbage Frist
JDK7 G1新型垃圾回收器. http://www.infoq.com/cn/articles/jdk7-garbage-first-collector
- JXTA 2: 具有高性能、海量伸缩性的 P2P 网络
这是来自developerWorks的一篇文章,地址是 https://www.ibm.com/developerworks/cn/java/j-jxta2/ ———————————————————— ...
- GAN网络
http://www.sohu.com/a/130252639_473283 高分辨率图像重建 https://zhuanlan.zhihu.com/p/25201511 生成式对抗网络GAN有哪些最 ...