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 ...
随机推荐
- ajaxfileupload.js异步上传
转载:https://www.cnblogs.com/labimeilexin/p/6742647.html jQuery插件之ajaxFileUpload ajaxFileUpload.js ...
- node服务器端模块化-commomjs
modele.js getmodule.js 用exports 返回的是一个对象中的每个属性
- java编程--04比较几个常用的日期时间相关类的区别
第一篇,介绍日期的比较 第二篇,介绍日期的格式化 第三篇,介绍关于日期常用的计算 第四篇,比较几个常用的日期时间相关类的区别 第五篇,jdk9对日期类进行了更新,写一些i自己的学习心得. 下面以一组思 ...
- Android NDK开发 环境配置(一) 之多重CPU的兼容性
今天我学习Android Studio当中的NDK,为什么要学习NDK呢,是因为领导给我提了一个BUG,这个BUG就是Android 多重CPU怎样兼容性,我现在先说一下,Android Studio ...
- 性能测试工具Jmeter01-简介
Jmeter介绍: Apache JMeter是Apache组织的开放源代码项目,是一个纯Java桌面应用,用于压力测试和性能测试.最初被设计用于Web应用测试后来扩展到其它测试领域 Jmeter有啥 ...
- Murano Weekly Meeting 2016.05.10
Meeting time: 2016.May.10 1:00~2:00 Chairperson: Serg Melikyan, from Mirantis Meeting summary: 1. m ...
- 使用python将元组转换成列表,并替换其中元素
aa = (1, 2, 3, 4, 5, 6) b = [(x == 5 and 8 or x) for x in aa] z = map(lambda x: 8 if x == 5 else x, ...
- PHP+jQuery实现翻板抽奖(中奖概率算法)
在电视节目中有一种抽奖形式暂且叫做翻板抽奖,台上有一个墙面,墙面放置几个大方块,主持人或者抽奖者翻开对应的方块即可揭晓中奖结果.类似的抽奖形式还可以应用在WEB中,本文将使用PHP+jQuery为您讲 ...
- hduoj 2955Robberies
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 设置windows 10 wifi
1.cmd 管理员 2.执行:netsh wlan set hostednetwork mode=allow ssid=test key=123456789 3.执行:netsh wlan start ...