Mobile phones
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 19786   Accepted: 9133

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

Source

【思路】
二维树状数组裸题
【code】
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a,x,y,k,l,r,b,t,s;
int sz[][]; int lowbit(int x)
{
return x&-x;
}
void add(int x,int y,int k)
{
for(int i=x;i<=s;i+=lowbit(i))
for(int j=y;j<=s;j+=lowbit(j))
sz[i][j]+=k;
}
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+=sz[i][j];
return ans;
}
int main()
{
while(scanf("%d",&a)!=EOF)
{
if(a==){
scanf("%d",&s);
memset(sz,,sizeof());
}
if(a==)
{
scanf("%d%d%d",&x,&y,&k);
add(x+,y+,k);
}
if(a==)
{
scanf("%d%d%d%d",&l,&b,&r,&t);
printf("%d\n",sum(r+,t+)-sum(l,t+)-sum(r+,b)+sum(l,b));
}
if(a==)break;
}
return ;
}

poj1195 Mobile phones的更多相关文章

  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. 【POJ1195】【二维树状数组】Mobile phones

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

  4. Mobile phones(poj1195)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 18453   Accepted: 8542 De ...

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

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

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

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

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

                                                                  Mobile phones Time Limit: 5000MS   Mem ...

  8. C. Mobile phones

    Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...

  9. (Pre sell) ZOPO ZP998 (C2 II) 5.5 inch smart phone True Octa Core MTK6592 1920X1080 FHD screen 401 ppi 2GB/32GB 14.0Mp camera-in Mobile Phones from Electronics on Aliexpress.com

    (Pre sell) ZOPO ZP998 (C2 II) 5.5 inch smart phone True Octa Core MTK6592 1920X1080 FHD screen 401 p ...

随机推荐

  1. typedef struct与struct定义结构体

    今天在定义结构体的时候发现typedef struct与struct定义结构体有一些不同之处: 结构也是一种数据类型, 能够使用结构变量, 因此,  象其他 类型的变量一样, 在使用结构变量时要先对其 ...

  2. 关于安装oracle 11g client 出现安装先决条件检查全部失败

    本文转自:https://blog.csdn.net/iloli/article/details/45244159 今天我在安装Oracle11gClient时,全部显示成N/A,Oracle无法执行 ...

  3. Centos 7 远程桌面客户端

    在centos下面要远程连接windows,有人说用rdesktop,但是好像centos 7没有,对从源代码编译也不大感兴趣. 幸好还有人提醒, https://geekblood.com/2014 ...

  4. items" does not support runtime expression

    <%@taglib prefix="c" uri="http://java.sun.com/jstl/core"%> 更改为  <%@tagl ...

  5. python 安装protobuf

    安装准备:python和protoc(编译proto到各个语言) 下载protobuf源代码(各种语言实现):https://github.com/google/protobuf  1.到Python ...

  6. Angualr 实现复选框全选功能

    html <html lang="en"> <head> <meta charset="UTF-8"> <title& ...

  7. Java8中 Date和LocalDateTime的相互转换

    一.在Java 8中将Date转换为LocalDateTime 方法1: 将Date转换为LocalDatetime,我们可以使用以下方法: 1.从日期获取ZonedDateTime并使用其方法toL ...

  8. mysql 5.5主从复制配置

    首先将主库现有的要实现主从的数据库原原本本地复制到从库上,目的是一开始就让主从同步,让binlog日志从最新的记录开始同步! 备份: 方法1:快捷导出所要的库如(库goods)[注意:该方法仅适合My ...

  9. ios 添加全屏返回手势

    1 建立导航控制器 2.导航控制器添加如下代码 - (void)viewDidLoad { [super viewDidLoad]; id target = self.interactivePopGe ...

  10. Jquery和JS的区别

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...