题目链接:

https://vjudge.net/problem/POJ-1195

题目大意:

直接维护二维树状数组

注意横纵坐标全部需要加1,因为树状数组从(1,1)开始

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<list>
#include<deque>
#include<sstream>
#include<cctype>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, s, t) for(int i = (s); i < (t); i++)
using namespace std;
typedef long long ll;
int T, n, m, cases;
int num[][];
int lowbit(int x)
{
return x & (-x);
}
///修改num[x][y] = d
void add(int x, int y, int d)
{
for(int i = x; i <= n; i += lowbit(i))
{
for(int j = y; j <= n; j += lowbit(j))
num[i][j] += d;
}
}
///计算顶点为(1, 1)(x, y)的数总和
int sum(int x, int y)
{
int ans = ;
for(int i = x; i > ; i -= lowbit(i))
{
for(int j = y; j > ; j -= lowbit(j))
ans += num[i][j];
}
return ans;
}
int main()
{
int t, x1, y1, x2, y2, d;
while(cin >> t >> n)
{
memset(num, , sizeof(num));
while(cin >> t)
{
if(t == )break;
else if(t == )
{
scanf("%d%d%d", &x1, &y1, &d);
x1++, y1++;
add(x1, y1, d);
}
else if(t == )
{
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
x1++, y1++, x2++, y2++;
cout<<(sum(x2, y2) - sum(x2, y1 - ) - sum(x1 - , y2) + sum(x1 - , y1 - ))<<endl;
}
}
}
return ;
}

POJ-1195 Mobile phones---裸的二维树状数组(注意下标从1,1开始)的更多相关文章

  1. [poj2155]Matrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25004   Accepted: 9261 Descripti ...

  2. 二维树状数组——SuperBrother打鼹鼠(Vijos1512)

    树状数组(BIT)是一个查询和修改复杂度都为log(n)的数据结构,主要用于查询任意两位之间的所有元素之和,其编程简单,很容易被实现.而且可以很容易地扩展到二维.让我们来看一道很裸的二维树状数组题: ...

  3. bzoj 1452: [JSOI2009]Count ——二维树状数组

    escription Input Output Sample Input Sample Output 1 2 HINT ———————————————————————————————————————— ...

  4. 二维树状数组+差分【p4514】上帝造题的七分钟

    Description "第一分钟,X说,要有矩阵,于是便有了一个里面写满了\(0\)的\(n\times m\)矩阵. 第二分钟,L说,要能修改,于是便有了将左上角为\((a,b)\),右 ...

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

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

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

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

  7. POJ 1195 Mobile phones (二维树状数组)

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

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

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

  9. POJ 1195 Mobile phones【二维树状数组】

    <题目链接> 题目大意: 一个由数字构成的大矩阵,开始是全0,能进行两种操作1) 对矩阵里的某个数加上一个整数(可正可负)2) 查询某个子矩阵里所有数字的和要求对每次查询,输出结果 解题分 ...

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

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

随机推荐

  1. C++容器嵌套实现动态二维数组(Vector2D)

    转: http://blog.csdn.net/Touch_Dream/article/details/74931891 #include<stdio.h> #include <io ...

  2. 10-----BBS论坛

    BBS论坛(十) 10.1.客户端权限验证功能完成 (1)cms/cms_profile 显示当前用户的角色和权限 <tr> <td>角色:</td> <td ...

  3. 异地clone RAC数据库 +ASM USE RMAN

    ###sample 如何在本地生成数据库的备份,并复制到DG库新环境(高级) 1. 首先确定本地文件系统(存放备份集)足够大,可以使用如下语句查询当前数据库实际的使用总大小 Rman 备份进度: se ...

  4. css预处理器 sass和stylus对比以及常用功能

    在众多的css预处理器语言中,sass和stylus算是十分优秀的两个.本文主要针对两者的常用功能做个简单的对比分析.在对比中了解二者的差异,同时帮助大家更好的掌握这两种预处理语言. 本文涉及到的sa ...

  5. SQL---MySQL数据库---试炼

    1.需求 user表 temp表 user_temp_salary表 1.1 查找每个人在2018年前2个月的平均工资信息 SELECT b.`name` AS userName,c.name AS ...

  6. 修改Matlab打开时的默认路径

    操作步骤 找到 matlabrc.m 文件 cd 'Matalb的安装路径' cd toolbox/local 编辑 matlabrc.m 文件 在文件末尾添加打开时要转到的目录,比如: shell ...

  7. js写ajax并解析json

    function down(t){  var req = createRequest();  //创建request req.open("GET","selectWord ...

  8. Ranking relevance in yahoo search (2016)论文阅读

    文章链接 https://www.kdd.org/kdd2016/papers/files/adf0361-yinA.pdf abstract 点击特征在长尾query上的稀疏性问题 基础相关性三大技 ...

  9. Redis Intro - Skiplist

    http://zhangtielei.com/posts/blog-redis-skiplist.html https://juejin.im/entry/59197a390ce4630069fbcf ...

  10. Django重新整理3

    Forms组件 1.在models.py中我们建立一个新的表关系: class UserInfo(models.Model): user=models.CharField(max_length=32) ...