题目连接:

题意:要求设计这样一个数据结构,支持下列操作

1.add(x,y,a).对二维数组的第x行,第y列加上a.

2.sum(l,b,r,t).求所有满足l<=x<=r,b<=y<=t,的数组元素的和

二位树状数组~

 #include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define loop(s,i,n) for(i = s;i <= n;i++)
#define lowbit(x) x&-x
using namespace std;
int c[][];
int n;
void add(int a,int b,int val)
{
int i,j;
for(i = a;i <= n;i += lowbit(i))
{
for(j = b;j <= n;j += lowbit(j))
c[i][j] += val;
}
} int sum(int a,int b)
{
int res = ;
int i,j;
for(i = a;i > ;i -= lowbit(i))
{
for(j = b;j > ;j -= lowbit(j))
res+=c[i][j];
}
return res;
}
int main()
{
int t,i,j,a,b,l,r;
while(~scanf("%d",&t) != EOF)
{
if(!t)
{
scanf("%d",&n);
loop(,i,n)
{
loop(,j,n)
c[i][j] = ;
}
}
if(t == )
{
scanf("%d %d %d",&a,&b,&l);
add(a+,b+,l);
}
else if(t == )
{
scanf("%d %d %d %d",&a,&b,&l,&r);
printf("%d\n",sum(a,b)+sum(l+,r+)-sum(a,r+)-sum(l+,b));
}
if(t == )
break;
}
return ;
}

poj 1195 mobile phone的更多相关文章

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

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

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

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

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

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

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

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

  5. ●POJ 1195 Mobile phones

    题链: http://poj.org/problem?id=1195 题解: 二维树状数组 #include<cstdio> #include<cstring> #includ ...

  6. poj 1195 Mobile phones 解题报告

    题目链接:http://poj.org/problem?id=1195 题目意思:有一部 mobie phone 基站,它的面积被分成一个个小正方形(1 * 1 的大小),所有的小正方形的面积构成了一 ...

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

                                                                  Mobile phones Time Limit: 5000MS   Mem ...

  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(二维BIT裸题)

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

  10. poj 1195 - Mobile phones(树状数组)

    二维的树状数组,,, 记得矩阵的求和运算要想好在写.... 代码如下: #include <cstdio> #include <cstdlib> #include <cm ...

随机推荐

  1. unity3d中dllimport方法的使用,以接入腾讯平台为例!!!

    说到有关dllimport方法可能还有很多人比较陌生,其实我自己也说不太清楚,大概说说什么时候要用它. 事实上功能类似于调用android的第三包,我们想要使用苹果上特定的api或者第三方平台的一些东 ...

  2. CF444C DZY Loves Colors

    考试完之后打的第一场CF,异常惨烈呀,又只做出了一题了.A题呆滞的看了很久,领悟到了出题者的暗示,应该就是两个点的时候最大吧,不然的话这题肯定特别难敲,YY一发交上去然后就过了.然后就在不停地YY B ...

  3. (1)opengl-nehe 4种框架

    http://www.yakergong.net/nehe/ 这个网站还是opengl方面比较权威的,作者叫nehe 这东西估计是要先装个ndk,然后才能运行代码 先睡觉! 以下内容参考自http:/ ...

  4. DFS+剪枝 HDOJ 5323 Solve this interesting problem

    题目传送门 /* 题意:告诉一个区间[L,R],问根节点的n是多少 DFS+剪枝:父亲节点有四种情况:[l, r + len],[l, r + len - 1],[l - len, r],[l - l ...

  5. Spark源码分析(二)-SparkContext创建

    原创文章,转载请注明: 转载自http://www.cnblogs.com/tovin/p/3872785.html  SparkContext是应用启动时创建的Spark上下文对象,是一个重要的入口 ...

  6. Android核心分析之二十二Android应用框架之Activity

    3 Activity设计框架 3.1 外特性空间的Activity    我们先来看看,android应用开发人员接触的外特性空间中的Activity,对于AMS来讲,这个Activity就是客服端的 ...

  7. java web线程池

    线程池 要知道在计算机中任何资源的创建,包括线程,都需要消耗系统资源的.在WEB服务中,对于web服 务器的响应速度必须要尽可能的快,这就容不得每次在用户提交请求按钮后,再创建线程提供服务 .为了减少 ...

  8. java开发--JavaScript

    http://www.cnblogs.com/hongten/archive/2011/03/21/1990121.html JavaScript表单验证电话号码,判断一个输入量是否为电话号码,通过正 ...

  9. IME 编程相关

    以下内容摘自http://msdn.microsoft.com/zh-cn/goglobal/bb688135.aspx 在 Win32 中处理输入语言的方法 Microsoft Developer ...

  10. 281. Zigzag Iterator

    题目: Given two 1d vectors, implement an iterator to return their elements alternately. For example, g ...