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. Django之sitemap

    ##########settings.py SITE_ID=1 # Application definition # taggit tag INSTALLED_APPS = [ 'myblog', ' ...

  2. OpenCV2马拉松第15圈——边缘检測(Laplace算子,LOG算子)

    收入囊中 拉普拉斯算子 LOG算子(高斯拉普拉斯算子) OpenCV Laplacian函数 构建自己的拉普拉斯算子 利用拉普拉斯算子进行图像的锐化 葵花宝典 在OpenCV2马拉松第14圈--边缘检 ...

  3. 安装部署zookeeper集群

    实验说明: 三台虚拟机做zookeeper集群,集群个数最好是奇数个,原理详见zookeeper 详解  安装zookeeper 请确保jdk 已安装好,否则无法启动  三台虚拟机IP分别为:192. ...

  4. 14 nginx 中配置 expires缓存提升网站负载

    一:nginx 中配置 expires缓存提升网站负载 对于网站的图片,尤其是新闻站, 图片一旦发布, 改动的可能是非常小的.我们希望 能否在用户访问一次后, 图片缓存在用户的浏览器端,且时间比较长的 ...

  5. 06 redis中set结构及命令详解

    集合 set 相关命令 集合的性质: 唯一性,无序性,确定性 注: 在string和link的命令中,可以通过range 来访问string中的某几个字符或某几个元素 但,因为集合的无序性,无法通过下 ...

  6. Epplus 使用案例

    //拷贝 sheet.Cells["6:12"].Copy(sheet.Cells["1:2"]); //边框无 sheet.Cells[(i * 6 + i ...

  7. EntityFramework走马观花之CRUD(下)

    我在Entity Framework系列文章的CRUD上篇中介绍了EF的数据查询,中篇谈到了EF的数据更新,下篇则聊聊EF实现CRUD的内部原理. 跟踪实体对象状态 在CRUD上篇和中篇谈到,为了实现 ...

  8. iOS界面-仿网易新闻左侧抽屉式交互 续(添加新闻内容页和评论页手势)

     本文转载至  http://blog.csdn.net/totogo2010/article/details/8637430       1.介绍 有的博友看了上篇博文iOS界面-仿网易新闻左侧抽屉 ...

  9. EasyPlayer RTSP Android安卓播放器实现视频源快速切换

    EasyPlayer现在支持多视频源快速切换了,我们介绍一下是如何实现的. 这个需求通常应用在一个客户端需要查看多个视频源的情况,比如多个监控场景轮播. 由于EasyPlayer的播放端已经放在Fra ...

  10. input file 选择Excel

    说明:开发环境 vs2012 asp.net mvc4 c# ,使用file 选择Excel文件 传到后台 使用Aspose.Cells获取Excel sheet页的名称 1.HTML代码 <% ...