Mobile phones

Time Limit: 5000 MS Memory Limit: 65536 KB

64-bit integer IO format: %I64d , %I64u Java class name: Main

[Submit] [Status] [Discuss]

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>
#include <string.h>
#include <stdio.h> using namespace std;
#define max 1025
int c[max][max];
int n; int lowbit(int x)
{
return x&-x;
} void update(int x,int y,int val)
{
for(int i=x;i<=n;i+=lowbit(i))
{
for(int j=y;j<=n;j+=lowbit(j))
{
c[i][j]+=val;
}
}
} int get_sum(int x,int y)
{
int s=;
for(int i=x;i>;i-=lowbit(i))
{
for(int j=y;j>;j-=lowbit(j))
{
s+=c[i][j];
}
}
return s;
} int main()
{
int i,j,s,T,x,y,x1,y1,val;
while()
{
scanf("%d",&T);
if (T==) break;
if (T==)
{
scanf("%d",&n);
memset(c,,sizeof(c));
}
if (T==)
{
scanf("%d%d%d",&x,&y,&val);
update(x+,y+,val); ///脚标从0开始 所以要+1喽~~~~
}
if (T==)
{
scanf("%d%d%d%d",&x,&y,&x1,&y1); ///同理
printf("%d\n",get_sum(x1+,y1+)+get_sum(x,y)-get_sum(x1+,y)-get_sum(x,y1+));
}
}
return ;
}

poj 1195 单点更新 区间求和的更多相关文章

  1. poj 3321 单点更新 区间求和

    Apple Tree Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u Java c ...

  2. POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)

    POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...

  3. POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)

    POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...

  4. LightOJ 1112 Curious Robin Hood (单点更新+区间求和)

    http://lightoj.com/volume_showproblem.php?problem=1112 题目大意: 1 i        将第i个数值输出,并将第i个值清0 2 i v     ...

  5. HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)

    HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...

  6. HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)

    HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...

  7. hdu 1166线段树 单点更新 区间求和

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  8. hdu1166(线段树单点更新&区间求和模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 题意:中文题诶- 思路:线段树单点更新,区间求和模板 代码: #include <iost ...

  9. hdu 1166 (单点更新+区间求和+裸题)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissi ...

随机推荐

  1. bowtie:短序列比对的新工具

    bowtie:短序列比对的新工具(转) (2014-11-17 22:15:24) 转载▼ 标签: 转载   原文地址:bowtie:短序列比对的新工具(转)作者:玉琪星兆 Bowtie是一个超级快速 ...

  2. 杭电1518 Square(构成正方形) 搜索

    HDOJ1518 Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. 10个办法让设计小白迅速get海报设计要点!

    对于设计师而言,海报和宣传单的设计,几乎是每一个设计师的必修课.如今网页上的 Banner.宣传和促销的数字海报,大多脱胎于我们所熟知的海报设计. 对于推销产品.连接客户,海报始终是一种最为有趣和实用 ...

  4. Memcache类

    class Memcache{ private static $mem = null; public function mem_create(){ self::$mem = new \Memcache ...

  5. ubuntu安装jre

    1)登录java官网,下载jre,并解压,解压后的jre文件夹移动到 /usr/lib/java 路径下 2)配置系统环境变量 JAVA_HOME CLASSPATH PATH 打开/etc/envi ...

  6. App上架流程[利用Archive进行上传]

    作者 M_Lee2016.01.22 10:47 写了14852字,被32人关注,获得了49个喜欢 [iOS]App上架流程[利用Archive进行上传] 字数2186 阅读507 评论3 喜欢9 今 ...

  7. 【密码学】轻松理解“加盐”的原理与java实现

    转自:https://blog.csdn.net/DavidHuang2017/article/details/80283469 一.什么是加盐? 1.背景 现在很多公司后台以hash值形式存储用户密 ...

  8. CMDB 配置管理数据库

  9. Django框架之Ajax和form组件

    一.Django框架之查漏补缺 1)models,字段概况 name = models.CharField(max_length=) age = models.IntegerField() price ...

  10. thymeleaf使用基础教程

    thymeleaf 是新一代的模板引擎,在spring4.0中推荐使用thymeleaf来做前端模版引擎. thymeleaf介绍 简单说, Thymeleaf 是一个跟 Velocity.FreeM ...