poj 1195 单点更新 区间求和
Mobile phones
Time Limit: 5000 MS Memory Limit: 65536 KB
64-bit integer IO format: %I64d , %I64u Java class name: Main
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
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
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 单点更新 区间求和的更多相关文章
- poj 3321 单点更新 区间求和
Apple Tree Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u Java c ...
- POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)
POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...
- POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)
POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...
- LightOJ 1112 Curious Robin Hood (单点更新+区间求和)
http://lightoj.com/volume_showproblem.php?problem=1112 题目大意: 1 i 将第i个数值输出,并将第i个值清0 2 i v ...
- HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)
HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...
- HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)
HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...
- hdu 1166线段树 单点更新 区间求和
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu1166(线段树单点更新&区间求和模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 题意:中文题诶- 思路:线段树单点更新,区间求和模板 代码: #include <iost ...
- hdu 1166 (单点更新+区间求和+裸题)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissi ...
随机推荐
- 洛谷3119 [USACO15JAN]草鉴定Grass Cownoisseur
原题链接 显然一个强连通分量里所有草场都可以走到,所以先用\(tarjan\)找强连通并缩点. 对于缩点后的\(DAG\),先复制一张新图出来,然后对于原图中的每条边的终点向新图中该边对应的那条边的起 ...
- mysql 优化之一
提升速度 show variables like 'innodb_flush_log_at_trx_commit'; 会显示为1 set global innodb_flush_log_at_trx ...
- jdbc元数据 以及自己动手写一个curd框架
数据库元数据(MetaData):数据库存储结构定义信息 (库.表.列 定义信息) ParameterMetaData 参数元数据 ---- 获得预编译SQL语句中 ? 信息 getParamet ...
- 用windows计划任务执行一些内容的写法,
用windows计划任务执行一些内容的写法, 以下示例: 1.创建ws对象 2.关闭java进程 3.执行bat文件 start.vbe文件内容 set ws=wscript.createobject ...
- object SparkStreaming_StateFul {
窗口查询 ) )).reduceByKeyAndWindow(_+_,_-_,Seconds(10),Seconds(15)) 每隔15s进行查询,查询为前10s的结果.这里的值必须为采集时间 ...
- WPF禁止拖拽窗口到边缘自动最大化
近期有个需求,可以通过拖拽改变窗口大小,但是不允许窗口最大化.最小化.拖到边缘的时候也不能自动最大化. 要想禁止拖拽窗口到边缘自动最大化,只要改注册表即可,但是系统所有应用都会被禁止. 1.运行reg ...
- 使用EventLog Analyzer进行VMware日志管理
- OpenCV-图像通道转换问题
OpenCV-MAT对象中使用plt.imshow(img[:,:,::-1])如何实现将第二轴反向? 系统平台:win10 x64 一.明确几个概念: 1.OpenCV内部每个通道并没有固定对应某种 ...
- 2019.01.19 codeforces915E.Physical Education Lessons(ODT)
传送门 ODT水题(当然可以上线段树) 支持区间01覆盖,询问全局1的个数. 思路:直接上ODTODTODT. 不会的点这里 代码: #include<bits/stdc++.h> #de ...
- window.frames
// 点击事件 function zTreeOnClick(event, treeId, treeNode) { id = treeNode.id; window.frames["treeF ...