版权声明:本文为博主原创文章,未经博主同意不得转载。 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. 如何用手机访问电脑上的html文件

    如何用手机访问电脑上的html文件 梦唪 | 浏览 3876 次 推荐于2016-03-26 08:08:58   最佳答案   1,你得搭建服务器,用Apache或者IIS.2,把HTML文件放到服 ...

  2. hadoop 调试mapperduce

    问题描述 运行hadoop的MapReduce示例,在running job卡住 在页面中显示一直处于 ACCEPTED Applications 状态 修改日志级别export HADOOP_ROO ...

  3. shell30题之第一题

    1.1.1 Shell面试题1:批量生成随机字符文件名案例 使用for循环在/oldboy目录下批量创建10个html文件,其中每个文件需要包含10个随机小写字母加固定字符串oldboy,名称示例如下 ...

  4. 【学习ATX基于uiautomator2】之API操作Android方法

    具体API可参考:<uiautomator2>以及参考github官方文档 感谢:Ricky_Frog <Python+uiautomator2手机UI自动化测试实战 -- 2. 用 ...

  5. tuning 03 Sizing the Share pool

    share pool : (组成) library cache: stores shared sql and pl/sql code (包含 statement text, parsed code, ...

  6. jQuery常用技巧

      1.关于页面元素的引用 通过jquery的$()引用元素包括通过id.class.元素名以及元素的层级关系及dom或者xpath条件等方法,且返回的对象为jquery对象(集合对象),不能直接调用 ...

  7. A Deep Compositional Framework for Human-like Language Acquisition in Virtual Environment

    论文地址:https://128.84.21.199/abs/1703.09831 这篇论文来自于百度的机器学习研究院,作者为:徐伟.余昊男.张海超 这篇论文用了多种技术的组合: reinforcem ...

  8. 第一百五十五节,封装库--JavaScript,轮播器

    封装库--JavaScript,轮播器 html <div id="banner"> <img src="img/banner1.jpg" a ...

  9. Sql Server数据批量更新

    UPDATE S SET S.[name]=T.[name],S.[sch_id]=T.[sch_id],S.[sex]=T.[sex],S.[isOk]=T.[isOk] FROM [Student ...

  10. Alpha matting算法发展

    一.抠图算法简介 Alpha matting算法研究的是如何将一幅图像中的前景信息和背景信息分离的问题,即抠图.这类问题是数字图像处理与数字图像编辑领域中的一类经典问题,广泛应用于视频编缉与视频分割领 ...