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 ...
随机推荐
- 长时间没有操作putty就会断开连接是怎么回事?
seconds between keepalives 设置为10就好了, 这个值有什么含义,服务器为了节省资源采取了一些措施,其中一条就是如果检测一个会话(session)几分钟或者几小时没有数据流入 ...
- jquery 进阶 bootstrap
. 样式操作 . 操作class . 操作CSS属性的 .css("color") .css("color", "green") .css( ...
- 2Y - sort
给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且都处于区间[-5000 ...
- 安卓个性化 Button
1.加入属性 android:background="@drawable/btn_selector" 2.drawable 下创建btn_selector.xml <?xml ...
- 转:百度MySql5.7安装配置
原文地址:http://jingyan.baidu.com/article/8cdccae946133f315513cd6a.html MySQL 5.7以上版本的配置和以前有所不同,在这里与大家分享 ...
- [Jmeter] 将参数从Jenkins传递给Jmeter
Configuration in Jmeter Configuration in Jenkins
- spring 的 ApplicationContext.getBean(type) 无法获取bean,报错
具体问题请看 https://q.cnblogs.com/q/108101/ 研究了两天: 经过上文中的排除法: 造成问题的原因是要获取的bean 中 有被切入的方法.. 就是可能该类会使用反射生 ...
- luaFramework
BeginStaticLibs 参考CustomSettings.cs public static List<Type> staticClassTypes = new List<T ...
- js之function
function* function* 这种声明方式(function关键字后跟一个星号)会定义一个生成器函数 (generator function),它返回一个 Generator 对象. 你 ...
- ServiceDesk Plus解析内容,简化工单管理