POJ1195--Mobile phones(基础二维BIT)
Description
Write a program, which receives these reports and answers queries about the current total number of active mobile phones in any rectangle-shaped area.
Input

The values will always be in range, so there is no need to check them. In particular, if A is negative, it can be assumed that it will not reduce the square value below zero. The indexing starts at 0, e.g. for a table of size 4 * 4, we have 0 <= X <= 3 and 0 <= Y <= 3.
Table size: 1 * 1 <= S * S <= 1024 * 1024
Cell value V at any time: 0 <= V <= 32767
Update amount: -32768 <= A <= 32767
No of instructions in input: 3 <= U <= 60002
Maximum number of phones in the whole table: M= 2^30
Output
Sample Input
0 4
1 1 2 3
2 0 0 2 2
1 1 1 2
1 1 2 -1
2 1 1 2 3
3
Sample Output
3
4
#include<iostream>
using namespace std;
int s[][];
int n;
int lowbit(int d){
return d&(-d);
}
int getSum(int a,int b){
int ans=;
for(int i=a;i>;i-=lowbit(i)){
for(int j=b;j>;j-=lowbit(j)){
ans+=s[i][j];
}
}
return ans;
}
void update(int a,int b,int d){
for(int i=a;i<=n;i+=lowbit(i)){
for(int j=b;j<=n;j+=lowbit(j)){
s[i][j]+=d;
}
}
}
int main(){
cin>>n>>n;
int c;
while(cin>>c&&c!=){
if(c==){
int x,y,z;
cin>>x>>y>>z;
x++;y++;
update(x,y,z);
}
else{
int w,x,y,z;
cin>>w>>x>>y>>z;
w++;x++;y++;z++;
cout<<getSum(y,z)-getSum(y,x-)-getSum(w-,z)+getSum(w-,x-)<<endl;
}
}
return ;
}
POJ1195--Mobile phones(基础二维BIT)的更多相关文章
- POJ1195 Mobile phones 【二维线段树】
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14291 Accepted: 6644 De ...
- POJ1195 Mobile phones 【二维树状数组】
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14288 Accepted: 6642 De ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- poj 1195:Mobile phones(二维线段树,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14391 Accepted: 6685 De ...
- POJ 1195 Mobile phones(二维树状数组)
Mobile phones Time Limit: 5000MS Mem ...
- (简单) 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(二维BIT裸题)
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ-1195 Mobile phones---裸的二维树状数组(注意下标从1,1开始)
题目链接: https://vjudge.net/problem/POJ-1195 题目大意: 直接维护二维树状数组 注意横纵坐标全部需要加1,因为树状数组从(1,1)开始 #include<c ...
- POJ 1195 Mobile phones【 二维树状数组 】
题意:基础的二维数组,注意 0 + lowbit(0)会陷入无限循环----- 之前做一道一维的一直tle,就是因为这个-------------------------- #include<i ...
随机推荐
- laravel 门面的介绍和使用
#上文讲述了laravel中怎么用容器依赖注入类的示例.其实在服务提供者上面在封装一层静态调用,这就是门面.静态调用门面,返回了容器中注册的别名和实例. #下面是测试的示例 #先创建要操作的类 < ...
- 小明A+B
/* 小明今年3岁了, 现在他已经能够认识100以内的非负整数, 并且能够进行100以内的非负整数的加法计算. 对于大于等于100的整数, 小明仅保留该数的最后两位进行计算, 如果计算结果大于等于10 ...
- BZOJ1051或洛谷2341 [HAOI2006]受欢迎的牛
BZOJ原题链接 洛谷原题链接 显然在一个强连通分量里的奶牛都可以相互喜欢,所以可以用\(tarjan\)求强连通并缩点. 要求明星奶牛必须被所有人喜欢,显然缩点后的图必须满足只有一个点没有出度,因为 ...
- 手机端适配方案 媒体查询和flexbale
方法一 flexible 一.npm 包安装 lib-flexible 淘宝适配方案 px2rem px自动转rem npm install lib-flexible --save npm insta ...
- PC 上的 LVM 灾难修复
LVM 介绍 LVM 简介 LVM 是逻辑盘卷管理(Logical Volume Manager)的简称,最早是 IBM 为 AIX 研发的存储管理机制.LVM 通过在硬盘和分区之间建立一个逻辑层,可 ...
- [SoapUI] 从Map里面不想要的键值对
def keysToRemoveForBoss = ["RequestIdBmk", "RequestIdTest"] def extraInfoMapForB ...
- JSR 规范目录
JSR 规范目录 一.Servlet 规范 1.1 Servlet 2.x 规范 1.2 Servlet 3.x 规范 - 注解和异步请求规范 每天用心记录一点点.内容也许不重要,但习惯很重要!
- mac install brew
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" ...
- sqlserver sql 循环
通过临时表进行sql循环 -----------创建临时表-------------- SELECT * INTO #tempfensitocity FROM( SELECT * FROM dbo.S ...
- 安装ubuntu16.04的时候出现的detecting file system
解决问题方法是,进入主界面执行,如下操作即可: sudo umount -l /isodevice