题目连接:

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

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. 电信SDK Pay函数里面System.out.print 无输出消息

    private void Pay(HashMap<String, String> payParams){ System.out.print("----------Pay Dian ...

  2. 【中国互联网不眠夜】Struts2漏洞百出,OneRASP鼎力相助

    Struts2是一款优秀的网站框架,在互联网上有十分广泛的应用,近期apache官方发布了高危漏洞通告Apache Struts 任意代码执行漏洞(CVE-2016-3081,S2-032),该漏洞风 ...

  3. P==NP??

    注:基础知识见下方 下面是关于P==NP ???  一些讨论,挺好玩的. 1. 首先强调一下数学上还没有证明这个问题!但是我们看看其他角度来看这个问题. 其次,心理上来说,要是可以证明P==NP那么早 ...

  4. POJ 2513 Colored Sticks (离散化+并查集+欧拉通路)

    下面两个写得很清楚了,就不在赘述. http://blog.sina.com.cn/s/blog_5cd4cccf0100apd1.htmlhttp://www.cnblogs.com/lyy2890 ...

  5. SQL Server 脚本

    创建数据库: --创建数据库 CREATE DATABASE Accounting -- 新数据库的名称 ON --主文件 ( NAME = 'Accounting', --文件名 FILENAME ...

  6. Good Bye 2015 B. New Year and Old Property 计数问题

    B. New Year and Old Property   The year 2015 is almost over. Limak is a little polar bear. He has re ...

  7. The first day of HTML

    这是韩顺平老师的<轻松搞定网页设计(html.css.js)>,讲的还凑合,仅作入门.决定还是做好笔记,记录学习的过程,这是HTML的第一天. HTML(HyperText Mark-up ...

  8. appium自动化测试中获取toast消息的解决方法【转】

    http://blog.csdn.net/hqzxsc2006/article/details/50036911 待实践.. 解决方法:appium下切换selendroid模式去获取Android的 ...

  9. mq_open

    NAME mq_open - 打开一个消息队列 (REALTIME) SYNOPSIS #include <mqueue.h> mqd_t mq_open(const char *name ...

  10. 使用yum安装CDH Hadoop集群

    使用yum安装CDH Hadoop集群 2013.04.06 Update: 2014.07.21 添加 lzo 的安装 2014.05.20 修改cdh4为cdh5进行安装. 2014.10.22  ...