版权声明:本文为博主原创文章,未经博主同意不得转载。 https://blog.csdn.net/u013912596/article/details/33802561

题目链接:

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 【二维树状数组】的更多相关文章

  1. POJ 1195:Mobile phones 二维树状数组

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 16893   Accepted: 7789 De ...

  2. 【poj1195】Mobile phones(二维树状数组)

    题目链接:http://poj.org/problem?id=1195 [题意] 给出一个全0的矩阵,然后一些操作 0 S:初始化矩阵,维数是S*S,值全为0,这个操作只有最开始出现一次 1 X Y ...

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

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

  4. Mobile phones_二维树状数组

    [题意]给你一个矩阵(初始化为0)和一些操作,1 x y a表示在arr[x][y]加上a,2 l b r t 表示求左上角为(l,b),右下角为(r,t)的矩阵的和. [思路]帮助更好理解树状数组. ...

  5. poj1195Mobile phones(二维树状数组)

    http://poj.org/problem?id=1195 模版题 i写成k了 找了一个多小时没找出来.. #include <iostream> #include<cstring ...

  6. poj_1195Mobile phones,二维树状数组

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...

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

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

  8. 【POJ1195】【二维树状数组】Mobile phones

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

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

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

随机推荐

  1. Post+Get方式接口测试代码编写

    详细代码如下 package testproject; import java.io.BufferedReader; import java.io.IOException; import java.i ...

  2. 【Android】利用Fiddler进行抓包详解教程。抓取接口以及数据,可以抓真实安卓手机或者模拟器。

    大家都知道抓包的方法很多.我这里给大家介绍介绍一种,利用fiddler进行抓包,当然比如Wireshark也可以抓包,我们这里不做介绍.我这里演示的是fiddler+天天模拟器,当然真实安卓手机也是一 ...

  3. 结构体sockadrr、sockaddr_in、in_addr的定义

    /* Internet address.  */typedef uint32_t in_addr_t;struct in_addr  {    in_addr_t s_addr;  };  typed ...

  4. Android最流行的网络框架(原创)

    Android程序最重要的模块就是网络部分,如何从网络上下载数据,如何将处理过的数据上传至网络,往往是android程序的关键环节.        Android原生提供基于HttpClient和Ht ...

  5. php max_execution_time执行时间问题

    php.ini 中缺省的最长执行时间是 30 秒,这是由 php.ini 中的 max_execution_time 变量指定,倘若你有一个需要颇多时间才能完成的工作,例如要发送很多电子邮件给大量收件 ...

  6. 阿里云经典网络和专有 专有自己设置网络和私网IP

    阿里云网络系列之经典网络和专有网络   驻云科技 2016-07-29 13:43:44 浏览45005 评论9 云栖社区 nginx 安全与风控 系统软件 编程语言 数据存储与数据库 系统研发与运维 ...

  7. Educational Codeforces Round 22 E. Army Creation 主席树 或 分块

    http://codeforces.com/contest/813/problem/E 题目大意: 给出长度为n的数组和k,  大小是1e5级别. 要求在线询问区间[l, r]权值,  权值定义为对于 ...

  8. js 判断数组

    这么基础的东西实在不应该再记录了,不过嘛,温故知新~就先从数据类型开始吧 js六大数据类型:number.string.object.Boolean.null.undefined string: 由单 ...

  9. wpf ComboBox设置默认值

    最新的wpf的ComboBox设置默认值得方法是,给VM中的数据集合第一个元素插入一个提示项目,比如:请选择一项,然后通过数据绑定可以实现默认选中第一项,下面我就贴一下示例代码: xaml页面: &l ...

  10. 计算机视觉中的边缘检测Edge Detection in Computer Vision

    计算机视觉中的边缘检测   边缘检测是计算机视觉中最重要的概念之一.这是一个很直观的概念,在一个图像上运行图像检测应该只输出边缘,与素描比较相似.我的目标不仅是清晰地解释边缘检测是怎样工作的,同时也提 ...