二维的树状数组,,,

记得矩阵的求和运算要想好在写。。。。

代码如下:

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <map> #define M 1100
#define INF 0x7fffffff
#define eps 1e-8
#define LL long long
#define LLU unsigned long long
#define lowbit(x) (x&-x) using namespace std; LL c[M][M];
int n;
void add(int x, int y, int a)
{
for(int i = x; i <= n; i+=lowbit(i))
for(int j = y; j <= n; j+=lowbit(j))
c[i][j] += a;
}
LL sum(int l, int r, int ll, int rr)
{
LL s1 = 0;
for(int i = l-1; i > 0; i-=lowbit(i))
for(int j = r-1; j > 0; j -= lowbit(j))
s1+=c[i][j];
LL s2 = 0;
for(int i = l-1; i > 0; i-=lowbit(i))
for(int j = rr; j > 0; j -= lowbit(j))
s2+=c[i][j];
LL s3 = 0;
for(int i = ll; i > 0; i-=lowbit(i))
for(int j = r-1; j > 0; j -= lowbit(j))
s3+=c[i][j];
LL s = 0;
for(int i = ll; i > 0; i-=lowbit(i))
for(int j = rr; j > 0; j-=lowbit(j))
s+=c[i][j];
return s+s1-s2-s3;
}
int main ()
{
int t, x, y, a, l, r, ll, rr;
scanf("%d%d", &t, &n);
while(scanf("%d", &t), t!=3)
{
if(t==1)
{
scanf("%d%d%d", &x, &y, &a);
add(x+1, y+1, a);
}
else
{
scanf("%d%d%d%d", &l, &r, &ll, &rr);
printf("%lld\n", sum(l+1, r+1, ll+1, rr+1));
}
}
return 0;
}

poj 1195 - Mobile phones(树状数组)的更多相关文章

  1. POJ 1195 二维树状数组

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 18489   Accepted: 8558 De ...

  2. Mobile phones POJ - 1195 二维树状数组求和

    Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...

  3. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  4. poj 1195:Mobile phones(二维线段树,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14391   Accepted: 6685 De ...

  5. (简单) POJ 1195 Mobile phones,二维树状数组。

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  6. POJ 1195 Mobile phones(二维树状数组)

                                                                  Mobile phones Time Limit: 5000MS   Mem ...

  7. poj 1195 Mobile phones(二维树状数组)

    树状数组支持两种操作: Add(x, d)操作:   让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...

  8. POJ 1195 Mobile phones (二维树状数组)

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  9. POJ 1195 Mobile phones (二维树状数组或线段树)

    偶然发现这题还没A掉............速速解决了............. 树状数组和线段树比较下,线段树是在是太冗余了,以后能用树状数组还是尽量用......... #include < ...

随机推荐

  1. Android 手机自动化测试工具有哪几种?

    1.Monkey是Android SDK自带的测试工具,在测试过程中会向系统发送伪随机的用户事件流,如按键输入.触摸屏输入.手势输入等),实现对正在开发的应用程序进行压力测试,也有日志输出.实际上该工 ...

  2. 如何去掉Eclipse里面自动追加的一些注释!!!内详

    比如我创建一个类,勾选了自动生成main函数.他就来一个// TODO Auto-generated method stub比如我输入"try"然后自动补完try catch bl ...

  3. Linux字符串截取和处理命令 cut、printf、awk、sed、sort、wc

    1. cut [选项] 文件名 -f  列号 #提取第几列(分隔符默认为\t) -d  分隔符 #指定分隔符 例如:cut -f 2 a.txt #截取文件a.txt内容的第二列(列号从1开始) cu ...

  4. Git之VS2010实践

    对于我们经常在VS2010下编程的开发人员来说,强大的SCM工具Git貌似对我们很陌生.对于Git,我在我的另一篇博客<Git学习笔记>中已做过介绍,下面我再简单介绍一下Git在VS201 ...

  5. 大型网站seo优化之行业网站seo优化具体操作思路

      第一部分:站内优化 第二部分:站外优化 第三部分:内容建设 第四部分:网站完善 一.站内优化 1.站内结构优化 2.内链策略 3.站内细节优化 4.网站地图设置 5.关键词竞争度分析 5.关键词部 ...

  6. ue4 FPaths各目录

    GetWrappedLaunchDir() 启动时的工作目录,因为马上要把工作目录改为下面所说的exe所在目录,所以会先把当前的缓存起来 FPlatformProcess::BaseDir() 这个是 ...

  7. javascript学习第四课函数

    函数也是一种数据类型:function类型 所以函数也可当作一个数据作参数传递 三种函数的声明示例: 一般来讲,声明方式一和声明方式二比较常用,方式三比较少. 常用函数方式示例: 注意:虽然函数支持嵌 ...

  8. 《笨办法学C》笔记之基础语法

    这篇笔记不怎么系统,只记录自己比较生疏的知识 变量定义 类型 定义 格式化符号 备注 整数 int %d 长整型 long %ld 单精度浮点 float %f 双精度浮点 double %f 字符 ...

  9. C++写一个带参数运行的程序

    #include <string.h>#include <iostream>#include <cstdlib>using namespace std; int m ...

  10. C# 读取Excel文件里面的内容到DataSet

    摘要:读取Excel文件里面的内容到DataSet 代码: /// <summary> /// 读取Excel文件里面的内容到DataSet /// </summary> // ...