题目链接:http://poj.org/problem?id=1195

【题意】

给出一个全0的矩阵,然后一些操作
0 S:初始化矩阵,维数是S*S,值全为0,这个操作只有最开始出现一次
1 X Y A:对于矩阵的X,Y坐标增加A
2 L B R T:询问(L,B)到(R,T)区间内值的总和
3:结束对这个矩阵的操作
 
【思路】
二维树状数组单点更新+区域查询,可作为模板题。
注意坐标是从0开始,所以要+1
 
【代码】
 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;
const int N = ;
typedef long long LL;
int c[N][N], n;
int lowbit(int x)
{
return x & (-x);
}
void update(int x, int y, int num)
{
for(int i = x; i <= n; i += lowbit(i))
for(int j = y; j <= n; j += lowbit(j))
c[i][j] += num;
}
int query(int x, int y)
{
int sum = ;
for(int i = x; i > ; i -= lowbit(i))
for(int j = y; j > ; j -= lowbit(j))
sum += c[i][j];
return sum;
}
int main()
{
int i, m;
scanf("%d%d", &i, &n);
while(scanf("%d", &m), m != )
{
int x1, x2, y1, y2, num;
if(m == )
{
scanf("%d%d%d", &x1, &y1, &num);
x1++, y1++;
update(x1, y1, num);
}
else
{
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
x1++, y1++, x2++, y2++;
printf("%d\n", query(x2, y2) - query(x1 - , y2) - query(x2, y1 - ) + query(x1 - , y1 - ));
}
}
return ;
}

【poj1195】Mobile phones(二维树状数组)的更多相关文章

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

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

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

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

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

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

  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. (简单) POJ 1195 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. ios开发之手势动作状态细分state,同一视图加入两个手势

    1.比方拖拽一个视图.形成类似scrollView的翻页形式 在拖拽的方法里推断拖拽的状态state属性,依据状态不同运行自己须要的效果. 2.同一视图加入两个手势,须要使用手势的代理方法.同意此操作 ...

  2. ie6不能播放视频问题

    前几天做项目时碰到一个非常棘手的问题.在我自己本机的ie8上能正常播放视频的程序(ie6也能够),放用户的电脑上就是不能正常播放(可能是用户的机子系统太老或是别的什么原因.详细的我也不太清楚).没办法 ...

  3. What are the top 10 things that we should be informed about in life

    1.Realize that nobody cares, and if they do, you shouldn't care that they care. Got a new car? Nobod ...

  4. sql 基础查询集锦

    授权 GRANT All ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED ...

  5. 实现num1、num2交换,无中间变量

    num1=num1+num2; num2=num1-num2; num1=num1-num2;

  6. (4.2)SQL Server 客户端连接的问题

    转自:http://blog.51cto.com/jimshu/1395199 经常遇到 SQL Server 客户端无法连接到SQL Server 实例(服务).现在将这类问题归纳如下: 一.SQL ...

  7. Kettle-1-安装配置

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/wl101yjx/article/details/32921691 写在前面一: 数据仓库ETL工具有 ...

  8. PHP 数组教程 定义数组

    数组array是一组有序的变量,其中每个变量被叫做一个元素. 一.定义数组  可以用 array() 语言结构来新建一个数组.它接受一定数量用逗号分隔的 key => value 参数对.  a ...

  9. Spark 1.5新特性介绍

    一.DataFrame执行后端优化(Tungsten第一阶段) DataFrame可以说是整个Spark项目最核心的部分,在1.5这个开发周期内最大的变化就是Tungsten项目的第一阶段已经完成.主 ...

  10. Java泛型一:基本介绍和使用

    原文地址http://blog.csdn.net/lonelyroamer/article/details/7864531 现在开始深入学习java的泛型了,以前一直只是在集合中简单的使用泛型,根本就 ...