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. Fedora : multilib version problems found

    摘自:https://smjrifle.net/fedora-fix-multilib-version-problems/ This error was due to duplicate packag ...

  2. 利用gulp搭建less编译环境

       什么是less? 一种 动态 样式 语言. LESS 将 CSS 赋予了动态语言的特性,如 变量, 继承, 运算, 函数. LESS 既可以在 客户端 上运行 (支持IE 6+, Webkit, ...

  3. MySQL 索引 INDEX

    索引用于快速找出在某列中有特定值的行. 不使用索引,MySQL必须从第一条记录开始读完整个表,直到找到相关的行,表越大,查询数据所花费的时间就越多,如果表中查询的列有一个索引,MySQL能够快速到达一 ...

  4. abp项目中无法使用HttpContext.Current.Session[""]的问题

    web项目Global.asax.cs中加入如下代码 public override void Init() { this.PostAuthenticateRequest += (sender, e) ...

  5. python常用命令

    安装sudo easy_install pip 列出已安装的包pip freeze or pip list 导出requirements.txtpip freeze > <目录>/r ...

  6. [C#.Net]启动外部程序的几种常用方法汇总

    本文汇总了C#启动外部程序的几种常用方法,非常具有实用价值,主要包括如下几种方法: 1. 启动外部程序,不等待其退出. 2. 启动外部程序,等待其退出. 3. 启动外部程序,无限等待其退出. 4. 启 ...

  7. kbmmw 中虚拟文件操作入门

    kbmmw 中一直有一个功能,但是基本上都没有提过,但是在实际应用中,却非常有用,这个功能就是 虚拟文件包功能,他可以把一大堆文件保存到一个文件里面,方便后台管理. kbmmw 的虚拟文件在单元kbm ...

  8. Javascript php 异常捕获

    JavaScript try 语句允许我们定义在执行时进行错误测试的代码块. catch 语句允许我们定义当 try 代码块发生错误时,所执行的代码块. JavaScript 语句 try 和 cat ...

  9. Java泛型总结——吃透泛型开发

    什么是泛型 泛型是jdk5引入的类型机制,就是将类型参数化,它是早在1999年就制定的jsr14的实现. 泛型机制将类型转换时的类型检查从运行时提前到了编译时,使用泛型编写的代码比杂乱的使用objec ...

  10. 关于微信小程序中组件和页面对全局样式的继承性

    1.组件只能继承全局样式中的font和color(backgroundcolor不继承) 2.页面可以继承全局样式中所有样式