POJ 1195 二维树状数组
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 18489 | Accepted: 8558 |
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
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
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
//树状数组模板
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int flag,X,Y,A,L,B,R,T,S;
int squ[][];
int lowbit(int x)
{
return x&(-x);
}
void add(int idx,int idy,int val)
{
for(int i=idx;i<=;i+=lowbit(i))
{
for(int j=idy;j<=;j+=lowbit(j))
{
squ[i][j]+=val;
}
}
}
int sum(int idx,int idy)
{
int s=;
for(int i=idx;i>;i-=lowbit(i))
{
for(int j=idy;j>;j-=lowbit(j))
{
s+=squ[i][j];
}
}
return s;
}
int ans(int x1,int y1,int x2,int y2)
{
return (sum(x2,y2)-sum(x1-,y2)-sum(x2,y1-)+sum(x1-,y1-));
}
int main()
{
while(scanf("%d",&flag)&&flag!=)
{
if(flag==)
{
scanf("%d",&S);
memset(squ,,sizeof(squ));
}
else if(flag==)
{
scanf("%d%d%d",&X,&Y,&A);
if(A>=)
add(X+,Y+,A);
else
{
int num=ans(X+,Y+,X+,Y+);
add(X+,Y+,num+A>?A:-num);
}
}
else if(flag==)
{
scanf("%d%d%d%d",&L,&B,&R,&T);
printf("%d\n",ans(L+,B+,R+,T+));
}
}
return ;
}
POJ 1195 二维树状数组的更多相关文章
- Mobile phones POJ - 1195 二维树状数组求和
Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...
- poj 2029 二维树状数组
思路:简单树状数组 #include<map> #include<set> #include<cmath> #include<queue> #inclu ...
- poj 3378 二维树状数组
思路:直接用long long 保存会WA.用下高精度加法就行了. #include<map> #include<set> #include<cmath> #inc ...
- poj 2155 (二维树状数组 区间修改 求某点值)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 33682 Accepted: 12194 Descript ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- (简单) POJ 1195 Mobile phones,二维树状数组。
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ 1195 Mobile phones【二维树状数组】
<题目链接> 题目大意: 一个由数字构成的大矩阵,开始是全0,能进行两种操作1) 对矩阵里的某个数加上一个整数(可正可负)2) 查询某个子矩阵里所有数字的和要求对每次查询,输出结果 解题分 ...
- POJ 1195 Mobile phones (二维树状数组)
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ 1195:Mobile phones 二维树状数组
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 16893 Accepted: 7789 De ...
随机推荐
- 在SharePoint2010中用out-of-box的方式自定制Application Pages(AccessDenied,Confirmation,Error,Login,RequestAccess,Signout,WebDeleted)
在实际项目中需要对SharePoint2010中的AccessDenied页面进行自定制,于是乎上网搜索相关内容,经实际操作此方法可行,便以此文记录. 在SharePoint2010中,由于secur ...
- merge布局
当LayoutInflater遇到这个标签时,它会跳过它,并将<merge />内的元素添加到<merge />的父元素里.迷惑了吗?让我们用<merge />来替 ...
- 【项目经验】之——Controller向View传值
我们的ITOO进行了一大部分了,整体上来说还是比较顺利的.昨天进行了一次验收,大体上来说,我们新生这块还是可以的.不仅仅进行了学术上的交流,还进行了需求上的更新.也正是由于这一次,我有了解到了一个新的 ...
- vs2015 MFC工程添加消息响应函数
真不知道这PPT怎么描述的..最后窝找到了解决方法如上图.. 下次找MSDN解决问题好了..而且我们并不知道他所说的这个IDE到底是哪个厂商哪个版本的IDE这就很困惑 不过呢..它主要是让我们添加消息 ...
- JMeter监控Linux服务器资源案例
JMeter是一款压力测试工具,我们也可以用它来监控服务器资源使用情况.JMeter正常自带可以通过Tomcat的/manager/status来监控服务资源使用情况.这种情况只能监控Tomcat支持 ...
- 记一次小团队Git实践(下)
在上篇中,我们已经能基本使用git了,接下来继续更深入的挖掘一下git. 更多的配置自定义信息 除了前面讲的用户名和邮箱的配置,还可以自定义其他配置: # 自定义你喜欢的编辑器,可选 git conf ...
- JDK 伪异步编程(线程池)
伪异步IO编程 BIO主要的问题在于每当有一个新的客户端请求接入时,服务端必须创建一个新的线程处理新接入的客户端链路,一个线程只能处理一个客户端连接.在高性能服务器应用领域,往往需要面向成千上万个客户 ...
- shell-bash学习02运算、拼接、重定向
运算 let操作 可以直接执行基本的算术操作;使用时,变量名之前不需要再添加$; #!/bin/bash no1=4; no2=5; let result=no1+no2 echo $result 自 ...
- 07 JavaWeb
软件开发的两种架构:c/s和b/s * C/S client/server 客户端/服务器 例子:QQ 快播 暴风影音... ...
- 【转】linux network namespace 学习
原文地址:https://segmentfault.com/a/1190000004059167 介绍 在专业的网络世界中,经常使用到Virtual Routing and Forwarding(VR ...