题目链接: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. upsampling(上采样)& downsampled(降采样)

    缩小图像 缩小图像(或称为下采样(subsampled)或降采样(downsampled))的主要目的是两个: 使得图像符合显示区域的大小: 生成对应图像的缩略图: 下采样的原理: 对于一幅图像尺寸为 ...

  2. Keras网络层之卷积层

    卷积层 Cov1D层 keras.layers.convolutional.Conv1D(filters, kernel_size, strides=1, padding='valid', dilat ...

  3. 购物单问题—WPS使用excel

    ****     180.90       88折 ****      10.25       65折 ****      56.14        9折 ****     104.65        ...

  4. python全栈开发从入门到放弃之列表的内置方法

    1.列表切片 l=['a','b','c','d','e','f'] print(l[1:5]) # 根据索引号来切片,但顾头不顾尾 ['b', 'c', 'd', 'e'] print(l[1:5: ...

  5. poj2250

    #include<string.h> #include<stdio.h> #include<algorithm> #include<vector> #i ...

  6. ASP.NET MVC 4.0 中使用NPOI 2.2.0 按模板生成Excel报表

    使用 NPOI 你就可以在没有安装 Office 或者相应环境的机器上对 WORD/EXCEL 文档进行读写.NPOI是构建在POI 3.x版本之上的,它可以在没有安装Office的情况下对Word/ ...

  7. MySQL-checkpoint技术

    几个知识点: 缓冲池:缓存磁盘数据,通过内存速度弥补CPU速度和磁盘速度的鸿沟. 脏页:LRU列表中被修改的页,和磁盘上的数据不一致 刷新频率:每次有脏页就刷新,开销很大.需要一种刷新机制 数据丢失: ...

  8. com.android.tools.build:gradle:X.XX.XX:gradle.jar 插件无法下载问题

    在使用Android Studio 这个IDE时,出现com.android.tools.build:gradle:X.XX.XX:gradle.jar 插件无法下载问题 可能的原因就是网速不好或者依 ...

  9. 在Linux系统中使用蓝牙功能的基本方法

    首先确定硬件上有支持蓝牙的设备,然后运行如下命令,就可以开到我们的蓝牙设备了: lsusb 运行hciconfig可以看到:从上图可以看出,我们的蓝牙设备是hci0运行hcitool dev可以看到我 ...

  10. Record and accumulation

    最近有同学在准备校招的问题,问我几个问题,我觉得有必要把大家的问题汇总下: 1.在设计变量的while指挥时候,可以利用弹栈的特性以及Java传值 只是传递的副本  去控制 : https://www ...