POJ-1195 Mobile phones---裸的二维树状数组(注意下标从1,1开始)
题目链接:
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开始)的更多相关文章
- [poj2155]Matrix(二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 25004 Accepted: 9261 Descripti ...
- 二维树状数组——SuperBrother打鼹鼠(Vijos1512)
树状数组(BIT)是一个查询和修改复杂度都为log(n)的数据结构,主要用于查询任意两位之间的所有元素之和,其编程简单,很容易被实现.而且可以很容易地扩展到二维.让我们来看一道很裸的二维树状数组题: ...
- bzoj 1452: [JSOI2009]Count ——二维树状数组
escription Input Output Sample Input Sample Output 1 2 HINT ———————————————————————————————————————— ...
- 二维树状数组+差分【p4514】上帝造题的七分钟
Description "第一分钟,X说,要有矩阵,于是便有了一个里面写满了\(0\)的\(n\times m\)矩阵. 第二分钟,L说,要能修改,于是便有了将左上角为\((a,b)\),右 ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- (简单) POJ 1195 Mobile phones,二维树状数组。
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ 1195 Mobile phones (二维树状数组)
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ 1195:Mobile phones 二维树状数组
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 16893 Accepted: 7789 De ...
- POJ 1195 Mobile phones【二维树状数组】
<题目链接> 题目大意: 一个由数字构成的大矩阵,开始是全0,能进行两种操作1) 对矩阵里的某个数加上一个整数(可正可负)2) 查询某个子矩阵里所有数字的和要求对每次查询,输出结果 解题分 ...
- 【POJ1195】【二维树状数组】Mobile phones
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
随机推荐
- JavaScript trim 实现去除字符串首尾指定字符的简单方法
String.prototype.trim = function (char, type) { if (char) { if (type == 'left') { return this.replac ...
- XtraFinder
About System Integrity Protection in OS X 10.11 Apple's article . System Integrity Protection blocks ...
- esper(2)-事件类型
1.pojo package com.ebc.eventtype.pojo.pojo1; import cn.hutool.core.collection.CollUtil; import com.e ...
- vue父子组件通信(prop)
先定义子组件,注册prop接收父组件传递的值 <template> <div> <div>{{message}}(子组件)</div> </div ...
- java课后思考题(四)
1. 请运行以下示例代码StringPool.java,查看其输出结果.如何解释这样的输出结果?从中你能总结出什么? 输出结果: 结论: 在Java中,内容相同的字串常量(“Hello”)只保存一份以 ...
- Bootloader 跳转到 RT-Thread 或 FreeRTOS(基于 STM32)
Bootloader 跳转到 RT-Thread 或 FreeRTOS(基于 STM32) 作者:猾蚁 QQ:7376220一.Bootloader 程序1. 准备好升级程序项目,可以使用 STM32 ...
- SigmoidCrossEntropyLoss
http://blog.csdn.net/u012235274/article/details/51361290
- 【密码学】CSP的概念
CSP加密服务提供者(Cryptographic Service Provider)具有一下几个特点: CSP是真正执行密码运算的独立模块 物理上一个CSP由两部分组成:一个动态连接库,一个签名文件 ...
- SSH密钥登录原理
Client 发送请求 login 请求 --> Server 接受请求 --> 根据 authorized_key 文件中的对应 Client 的 ip 地址的公钥对一串随机数进行加密 ...
- IIS 伪静态 脚本映射 配置方法
首先,是IIS7.0的配置,由于Windows Server 2008操作系统默认的IIS版本为7.0,我们知道,IIS7.0与IIS6.0 核心注意的地方:先要将应用池设置为集成模式,修改OK后,再 ...