Description

Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The squares form an S * S matrix with the rows and columns numbered from 0 to S-1. Each square contains a base station. The number of active mobile phones inside a square can change because a phone is moved from a square to another or a phone is switched on or off. At times, each base station reports the change in the number of active phones to the main base station along with the row and the column of the matrix.

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 input is read from standard input as integers and the answers to the queries are written to standard output as integers. The input is encoded as follows. Each input comes on a separate line, and consists of one instruction integer and a number of parameter integers according to the following table. 

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

Your program should not answer anything to lines with an instruction other than 2. If the instruction is 2, then your program is expected to answer the query by writing the answer as a single line containing a single integer to standard 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)的更多相关文章

  1. POJ1195 Mobile phones 【二维线段树】

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14291   Accepted: 6644 De ...

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

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14288   Accepted: 6642 De ...

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

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

  4. poj 1195:Mobile phones(二维线段树,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14391   Accepted: 6685 De ...

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

                                                                  Mobile phones Time Limit: 5000MS   Mem ...

  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(二维BIT裸题)

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

  9. POJ-1195 Mobile phones---裸的二维树状数组(注意下标从1,1开始)

    题目链接: https://vjudge.net/problem/POJ-1195 题目大意: 直接维护二维树状数组 注意横纵坐标全部需要加1,因为树状数组从(1,1)开始 #include<c ...

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

    题意:基础的二维数组,注意 0 + lowbit(0)会陷入无限循环----- 之前做一道一维的一直tle,就是因为这个-------------------------- #include<i ...

随机推荐

  1. 长时间没有操作putty就会断开连接是怎么回事?

    seconds between keepalives 设置为10就好了, 这个值有什么含义,服务器为了节省资源采取了一些措施,其中一条就是如果检测一个会话(session)几分钟或者几小时没有数据流入 ...

  2. jquery 进阶 bootstrap

    . 样式操作 . 操作class . 操作CSS属性的 .css("color") .css("color", "green") .css( ...

  3. 2Y - sort

    给你n个整数,请按从大到小的顺序输出其中前m大的数.  Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且都处于区间[-5000 ...

  4. 安卓个性化 Button

    1.加入属性 android:background="@drawable/btn_selector" 2.drawable 下创建btn_selector.xml <?xml ...

  5. 转:百度MySql5.7安装配置

    原文地址:http://jingyan.baidu.com/article/8cdccae946133f315513cd6a.html MySQL 5.7以上版本的配置和以前有所不同,在这里与大家分享 ...

  6. [Jmeter] 将参数从Jenkins传递给Jmeter

    Configuration in Jmeter Configuration in Jenkins

  7. spring 的 ApplicationContext.getBean(type) 无法获取bean,报错

    具体问题请看   https://q.cnblogs.com/q/108101/ 研究了两天: 经过上文中的排除法: 造成问题的原因是要获取的bean 中 有被切入的方法.. 就是可能该类会使用反射生 ...

  8. luaFramework

    BeginStaticLibs  参考CustomSettings.cs public static List<Type> staticClassTypes = new List<T ...

  9. js之function

    function* function* 这种声明方式(function关键字后跟一个星号)会定义一个生成器函数 (generator function),它返回一个  Generator  对象. 你 ...

  10. ServiceDesk Plus解析内容,简化工单管理