POJ1195 Mobile phones(树状数组)

【题解】[ IOI 2001] Mobile Phones(二维树状数组) 题面 【题目描述】 假设TampereTampereTampere区域的第四代手机基地站运行如下。该区域被划分为一些正方形(方阵)。这些正方形构成一个SSS╳SSS的矩阵,矩阵行和列的编号从000到S−1S-1S−1。每个正方形包含一个基地站。由于一个手机可能从一个正方形移动到另一个正方形,或者手机可能开机或关机,所以,在一个正方形内正在使用的手机数目是随时变化的。有时,每个基地站需要将正在使用的... 阅读详情

Mobile phones
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 16729 Accepted: 7698

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



二维的树状数组应用,op为1则(x, y)区间加a,op为2则计算(x, y)电话数并输出。


AC代码:


#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
const int MAXN = 1100;
int a[MAXN][MAXN], n;
int lowbit(int x)
{
	return x & (-x);
}
void update(int x, int y, int v)
{
	for(int i = x; i <= n; i += lowbit(i))
		for(int j = y; j <= n; j += lowbit(j))
			a[i][j] += v;
}
int get_sum(int x, int y)
{
	int sum = 0;
	for(int i = x; i > 0; i -= lowbit(i))
		for(int j = y; j > 0; j -= lowbit(j))
			sum += a[i][j];
	return sum;
}
int main(int argc, char const *argv[])
{
	int op;
	while(scanf("%d", &op) != EOF && op != 3) {
		if(op == 0) {
			scanf("%d", &n);
			memset(a, 0, sizeof(a));
		}
		else if(op == 1) {
			int x, y, a;
			scanf("%d%d%d", &x, &y, &a);
			update(x + 1, y + 1, a);
		}
		else if(op == 2) {
			int l, b, r, t;
			scanf("%d%d%d%d", &l, &b, &r, &t);
			++l, ++b, ++r, ++t;
			int ans = get_sum(r, t) + get_sum(l - 1, b - 1) - get_sum(r, b - 1) - get_sum(l - 1, t);
			printf("%d\n", ans);
		}
	}
	return 0;
}


语义通信理论必看论文:Towards a Theory of Semantic Communication 了解语义通信发展必看的一篇文章 阅读详情

相关推荐

FinalShell连接Ubuntu报Connection refused?SSH服务排查与解决指南

SSH(Secure Shell)是远程登录Linux服务器的核心协议,其工作原理基于TCP三次握手建立加密通道。当客户端发起连接时,若目标端口无服务监听,内核将返回RST包,表现为Connection refused错误。理解这一机制对运维排查至关重要,可快速区分服务缺失与网络故障。在开发测试、虚拟机管理等场景中,SSH服务的正确配置直接影响远程操作效率。本文针对FinalShell连接Ubuntu时常见的Connection refused报错,深入剖析SSH服务安装、监听地址、防火墙放行及虚拟机网络模

weixin_29611239的博客 257

IOI2001 - 移动电话

   P1294 - 【IOI 2001 】移动电话 Description 假设Tampere地区的4G移动通信基站以如下方式运行。整个地区被划分成若干正方形格子。这些格子构成一个S * S的矩阵,它们的行,列编号都是从0到S-1.每一个格子中都有一个基站。每个格子中激活的手机数量可能改变,因为一部手机可能从一个格子移动到另一个格子,打开或者关闭。有时,某一座基站会向总站...

weixin_34008784的博客 290

java爬虫(爬取银行理财数据)

import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; imp

ROCK 2492

K - Mobile phones

Time Limit: 5000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u [Submit]   [Go Back]   [Status] Description

mr_lee 678

别再自己造轮子了!用MONAI Model Zoo里的预训练模型,5分钟搞定医学影像AI项目

本文介绍了如何利用MONAI Model Zoo中的预训练模型快速搭建医学影像AI项目,大幅节省开发时间和计算资源。通过实战案例展示了UNet、DenseNet121等核心模型的应用技巧,帮助临床医生和研究者5分钟内启动高质量医学影像分析,特别适合小样本场景下的病灶分割和分类任务。

weixin_33704234的博客 255

基于Simulink的永磁同步电机(PMSM)无位置传感器矢量控制与龙伯格观测器设计​

本文介绍了基于Simulink的永磁同步电机(PMSM)无位置传感器矢量控制方法,重点讲解了龙伯格观测器的设计与实现。主要内容包括:1)系统架构与数学推导,通过静止坐标系状态方程和极点配置构建观测器;2)Simulink建模步骤,从电机模型搭建到观测器核心代码实现;3)仿真结果对比分析,显示龙伯格观测器相比滑模观测器具有更好的平滑性和抗噪能力;4)工程部署建议,包括参数在线辨识、低速补偿策略和代码生成优化。该方法实现了全速域无感运行,稳态转速误差小于1%,为低成本高可靠性电机控制提供了有效解决方案。

amy_mhd的博客 174

Mobile phones ( IOI2001 )

思路:用二维前缀和做,所以可以用树状数组进行维护,时间复杂度大概为O(qlognlogn)op=2时求L<=x<=R&&B<=y<=T时所有[ x ][ y ]点上数字的总和。简单翻译一下:刚输入时op=0并给出n,结束时op=3。op=1时在[ x ][ y ]这个点加上A。

xuxizhe0104的博客 1426

静止无功补偿SVG的基本控制原理

上图是自励单变量控制框图,基本控制方式为,采集计算得到负载无功电流和SVG输出的无功电流的差值,经过PI调节作为功率角δ和固定的调制深度λ和调制波,经过PWM调制形成开关信号驱动SVG的功率电路。该控制方式使保持调制深度λ(即SVG电压的幅度)不变,通过调整δ来调整直流电压和无功,跟踪输出无功功率,直流电压就会大幅度随动,无功相应速度较慢。SVG通常有他励方式和自励方式,他励方式需要提供外部的直流电源,自励方式通过电网输出有功功率至SVG建立SVG的直流电压。δ为Us和Uc之间的相角差。

weixin_42668920的博客 2014

Mobile Phone(二维树状数组)

Mobile Phone My Tags   (Edit) Source : IOI 2001 Time limit : 5 sec Memory limit : 32 M Submitted : 1040, Accepted : 310 PROBLEM   Suppose that th

Ninaye的博客 323

利用Aspera高效批量下载NCBI SRA数据的完整指南

本文提供了利用Aspera高效批量下载NCBI SRA数据的完整指南。详细介绍了Aspera Connect的安装、ascp命令的参数解析、从EBI/ENA获取批量下载清单的方法,以及如何通过并行脚本和整合SRA Toolkit实现自动化极速下载,帮助生物信息学研究人员彻底告别传统低速下载方式。

weixin_29275257的博客 1281

ESP-IDF 5.4下esp32-camera组件编译报错?手把手教你解决头文件缺失问题

本文详细解析了ESP-IDF 5.4环境下esp32-camera组件编译时出现的头文件缺失问题,提供了从目录结构优化、CMake配置到VSCode智能感知设置的完整解决方案。针对第三方组件集成难题,文章特别强调了PRIV_REQUIRES依赖声明和路径配置的关键作用,帮助开发者高效解决编译错误并建立稳定的开发环境。

weixin_28829629的博客 315

【POJ 1195】 Mobile phones (树状数组)

【POJ 1195】 Mobile phones (树状数组) Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 16761   Accepted: 7713 Description Suppose that the

ACMer' 1869

Qt EGLFS 图形后端详解

EGLFS (EGL Full Screen) 是Qt框架在嵌入式Linux系统中的高性能图形显示后端,它提供了直接基于EGL和OpenGL ES的硬件加速渲染解决方案。

浩瀚之水的专栏 531

POJ 1195 Mobile phones(树状数组)

在一个初始矩阵map中进行操作 初始值为0 4种操作 输入0 后面跟着n为矩阵的size 为n*n 输入1 后面跟着 x y v 意思就是在 (x,y)位置的数增加 v 输入2 后面跟着 x1 y1 x2 y2 意思就是查询(x1 ,y1 )到(x2,y2)中的数的和 输入3 程序停止 update操作很简单  就是运用二维树状数组在(x,y)增加v就可以了 如果v getsum求和

DIOML的博客 413

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

POJ1195:Mobile phones(二维树状数组)

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 an

ACM!荣耀之路! 3662

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

POJ1195 Mobile phones【二维树状数组】

Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 25904 Accepted: 11812 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

海岛Blog 482

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

【poj 1195】Mobile phones 二维树状数组

Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 17500 Accepted: 8093Description Suppose that the fourth generation mobile phone base stations in the Tampere area

ATOD 830

【poj1195】Mobile phones(二维树状数组)

题目链接:http://poj.org/problem?id=1195 【题意】 给出一个全0的矩阵,然后一些操作 0 S:初始化矩阵,维数是S*S,值全为0,这个操作只有最开始出现一次 1 X Y A:对于矩阵的X,Y坐标增加A 2 L B R T:询问(L,B)到(R,T)区间内值的总和 3:结束对这个矩阵的操作 【思路】 二维树状数组单点更新+区域查询,可作为...

ayci54153的博客 112

二维树状数组 —— POJ 1195 Mobile phones

二维树状数组 —— POJ 1195 Mobile phones

大田二十 575

POJ 1195 Mobile phones 【二维树状数组】

传送门:POJ 1195 Mobile phones Time Limit: 5000MS Memory Limit: 65536K Problem Description Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The ar...

Waiting For You 187

POJ1195 Mobile phones 二维树状数组

题目链接:http://poj.org/problem?id=1195 题目大意:给出一个n*n的矩阵,两种操作:“1 x y v”表示将矩阵上的点(x,y)加上v;“2 x1 y1 x y”表示查询矩阵的和。 分析:和HDU2645 Stars类似,很裸的二维树状数组的题。 实现代码如下: #include #include #include using n

AC_Gibson的专栏 615

二维树状数组模板题 poj 1195 Mobile phones

给定一个矩阵和三种操作 1 a b x表示把[a,b]值加上x,2 L B R T表示L <= x <= R , B <= y <= T 求这个小矩形的面积 3表示输入结束

ACM_10000h的专栏 924

POJ 1195 Mobile Phones 二维树状数组

1 #include<iostream> 2 #include<math.h> 3 #include<string.h> 4 #include<queue> 5 #include<algorithm> 6 #include<cstdio> 7 #define rep(i,a,n) f...

b479093573011909的博客 201

POJ 1195 (Mobile phones) 二维树状数组

题目链接:http://poj.org/problem?id=1195 题意:给出一个矩阵及一些操作,求一些子矩阵的和。 思路:二维树状数组裸题,要注意下标从0开始,所以可以在输入后对每个坐标值都加1。 #include #include #include #include #include #include #include #include #include #include #

Interstellar_的博客 408

(POJ1195)Mobile phones <二维树状数组>

Mobile phones DescriptionSuppose 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 t

STILLxjy 587

poj1195 Mobile phones(二维树状数组)

http://poj.org/problem?id=1195 题意:(一大坨的题)给你4种操作,0代表输入矩阵的宽度建立矩阵,1代表对矩阵中第x行y列的数加上a,2代表对坐标点(l,b)~(r,t)矩阵内的所有点求和并输出,3代表退出。 思路:首先看教程,二维树状数组说白了就是横向为1,2,1,4,1,2,1,8这样的树状数组,纵向也为1,2,1,4,1,2,1,8这样的树状数组,

Iguodala的博客 471
上一篇: Codeforces Round #250 (Div. 2) 437C The Child and Toy(脑洞贪心)
下一篇: HDOJ1556 Color the ball(树状数组)
GKHack
博客等级 码龄12年 48粉丝 291原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址