版权声明:本文为博主原创文章,未经博主同意不得转载。 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. c3p0 APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks

    2018-01-04 15:02:03,319 ---com.mchange.v2.async.ThreadPoolAsynchronousRunner: com.mchange.v2.async.T ...

  2. linux内核开机logo显示调试

    要使内核支持开机logo显示需要配置内核 配置如下: make menuconfig: Device Drivers  --->     Graphics support  --->    ...

  3. Paxos发展、算法原理

    Paxos 发展史 Leslie Lamport所提出的Paxos算法是现代分布式系统中的一项重要的基础性技术,得到广泛的应用. Paxos的整个发展过程大概可以分为三个阶段: 第一阶段:萌芽期,大致 ...

  4. 本地连接linux虚拟机的方法

    1.给虚拟机添加一个ehtX: 2. 3.添加一个ethX 4. 5.设置使用的是哪一个网卡,ifconfig的时候变会得到相应的ip 6. 再在cmd那ping ifconfig出来的自动获取的ip ...

  5. PHP-preg_replace过滤字符串代码

    $str=preg_replace("/\s+/", " ", $str); //过滤多余回车       $str=preg_replace("/& ...

  6. SRM 719 Div 1 250 500

    250: 题目大意: 在一个N行无限大的网格图里,每经过一个格子都要付出一定的代价.同一行的每个格子代价相同. 给出起点和终点,求从起点到终点的付出的最少代价. 思路: 最优方案肯定是从起点沿竖直方向 ...

  7. 《Windows游戏编程大师技巧》学习笔记——关于创建显示表面

    1.如你所知,显示在屏幕上的图像仅仅只是是以某种格式存储在内存中的有色像素组成的矩阵.或是调色板化的或是RGB模式的.在不论什么一种情况下.要想做点什么你都必须知道如何绘制图到内存中,然而Direct ...

  8. 安装tomcat出现failed to install tomcat6 service错误及解决方法(转载)

    安装安装版tomcat会出现failed to install tomcat6 service ,check your setting and permissio的概率是非常低的,但是最近楼主就老出现 ...

  9. 修改一些IntelliJ IDEA 11的设置,使Eclipse的使用者更容易上手(转)

    用惯了Eclipse,再来使用IntelliJ IDEA真是很难适应. 设置1:字体 修改IDE的字体:设置-Appearance-Look and Feel-OverRide设置你想要的字体.我设置 ...

  10. CodeFirst中DbContext动态添加DbSet

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...