UVa Online Judge 12532 - Interval Product

UVa Online Judge 西班牙Valladolid 在线判官 和 uDebug使用简单教程 udebug使用在后面 https://uva.onlinejudge.org/ 1、这是主界面,如果你还没有账号,那么就点击图中的register。 2、然后就是填写信息,邮箱要用gmail,信息填写完成后点击下方的register 3、之后打开邮箱查看接受的邮件,并点击其中的链接完成注册确认,之后会转到uva oj,如果页面显示 your account is now acti... 阅读详情

UVA - 12532 Interval Product

http://acm.bnu.edu.cn/v3/problem_show.php?pid=27853

Interval Product

Time Limit: 2000ms
Memory Limit: 131072KB
This problem will be judged on UVA. Original ID: 12532
64-bit integer IO format: %lld Java class name: Main
Type:
None
 

[PDF Link]

It's normal to feel worried and tense the day before a programming contest. To relax, you went out for a drink with some friends in a nearby pub. To keep your mind sharp for the next day, you decided to play the following game. To start, your friends will give you a sequence of N integers X1, X2,..., XN. Then, there will be K rounds; at each round, your friends will issue a command, which can be:
  • a change command, when your friends want to change one of the values in the sequence; or
  • a product command, when your friends give you two values I, J and ask you if the product XI x XI+1 x ... x XJ-1 x XJ is positive, negative or zero.

Since you are at a pub, it was decided that the penalty for a wrong answer is to drink a pint of beer. You are worried this could affect you negatively at the next day's contest, and you don't want to check if Ballmer's peak theory is correct. Fortunately, your friends gave you the right to use your notebook. Since you trust more your coding skills than your math, you decided to write a program to help you in the game.

 

Input

Each test case is described using several lines. The first line contains two integers N and K, indicating respectively the number of elements in the sequence and the number of rounds of the game ( 1$ \le$N, K$ \le$105). The second line contains N integers Xi that represent the initial values of the sequence ( -100$ \le$Xi$ \le$100 for i = 1, 2,..., N). Each of the next K lines describes a command and starts with an uppercase letter that is either `C' or `P'. If the letter is `C', the line describes a change command, and the letter is followed by two integers I and V indicating that XI must receive the value V ( 1$ \le$I$ \le$N and -100$ \le$V$ \le$100). If the letter is `P', the line describes a product command, and the letter is followed by two integers I and J indicating that the product from XI to XJ, inclusive must be calculated ( 1$ \le$I$ \le$J$ \le$N). Within each test case there is at least one product command.

 

Output

For each test case output a line with a string representing the result of all the product commands in the test case. The i-th character of the string represents the result of the i-th product command. If the result of the command is positive the character must be `+' (plus); if the result is negative the character must be `-' (minus); if the result is zero the character must be `0' (zero).

 

Sample Input

 

4 6
-2 6 0 -1
C 1 10
P 1 4
C 3 7
P 2 2
C 4 -5
P 1 4
5 9
1 5 -2 4 3
P 1 2
P 1 5
C 4 -5
P 1 5
P 4 5
C 3 0
P 1 5
C 4 -5
C 4 -5

 

Sample Output

 

0+-
+-+-0


题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3977

题目大意:C时更新下标I处的值为V,P时计算下标I到J的数的乘积,若乘积为正输出+,乘积为负输出-,乘积为0输出0。

解题思路:裸线段树,T了很多次,注意更新和读取值函数的返回条件。

代码如下:

#include <cstdio>
#include <cstring>
const int maxn=100005;
int a[maxn],tr[4*maxn];
void build(int l,int r,int root)
{
	if(l==r)
	{
		scanf("%d",&a[l]);
		if(a[l]==0)
			tr[root]=0;
		else if(a[l]<0)
			tr[root]=-1;
		else
			tr[root]=1;
		return ;
	}
	int mid=(l+r)/2;
	build(l,mid,root*2);
	build(mid+1,r,root*2+1);
	tr[root]=tr[root*2]*tr[root*2+1];
}
void change(int l,int r,int x,int v,int root)
{
	if(l==r)
	{
		if(l==x)
		{
			a[l]=v;
			if(a[l]==0)
				tr[root]=0;
			else if(a[l]<0)
				tr[root]=-1;
			else
				tr[root]=1;
		}
		return ;
	}
	int mid=(l+r)/2;
	if(x<=mid)
	change(l,mid,x,v,root*2);
	else
	change(mid+1,r,x,v,root*2+1);
	tr[root]=tr[root*2]*tr[root*2+1];
}
int product(int l,int r,int x,int y,int root)
{
	if(l>=x&&r<=y)
		return tr[root];
	int mid=(l+r)/2,tm=1;
	if(x<=mid)
		tm*=product(l,mid,x,y,root*2);
	if(y>mid)
		tm*=product(mid+1,r,x,y,root*2+1);
	return tm;
}
int main()
{
	int n,k,x,y;
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		char c;
		int m=0;
		memset(a,0,sizeof(a));
		build(1,n,1);
		for(int i=0;i<k;i++)
		{
			getchar();
			scanf("%c%d%d",&c,&x,&y);
			if(c=='C')
			{
				if(a[x]==0&&y==0||a[x]<0&&y<0||a[x]>0&&y>0)
					continue;
				a[x]=y;
				change(1,n,x,y,1);
			}
			else
			{
				int tm=product(1,n,x,y,1);
				if(tm<0)
					printf("-");
				else if(tm==0)
					printf("0");
				else
					printf("+");
			}
		}
		printf("\n");
	}
	return 0;
}


UVa online judge 题目解答汇总 一直在做 UVa Online Judge 的题目,硬盘上有上百个题solution了,但从来没有把自己当时的思路记录下来。有些题还是很难的,过后再看,已经看不懂当时的程序了。所以决定重新整理,把每一道题的解法和思路一一记录,给自己留个记录,也给各位苦攻 UVa Online Judge 题目的同学一个帮助。 注意!这些都是题透!请认真考虑过,真的需要再打开看,由此造成解题乐趣的丧失概不在 阅读详情

相关推荐

UVA在线判题系统竞赛编程实战示例代码集

稳定性(Stability)若两个相等元素在排序前后相对位置不变,则称算法是稳定的。例如数组排序后应为而非。重要性体现于复合键排序:假设先按姓名排序,再按年龄排序。若第二趟排序不稳定,则会打乱第一趟的结果。归并排序天然稳定,而标准快排因交换可能导致不稳定。原地性(In-place)指算法执行过程中仅使用常数级额外内存($ O(1) $)。这对于内存受限环境(如嵌入式系统或大数组处理)至关重要。快速排序可通过原地分区实现,而归并排序通常需要 $ O(n) $ 辅助数组。

weixin_35636570的博客 739

UVa Online Judge(UVA OJ)

UVa Online Judge(UVA OJ)

青少年趣味编程 2842

UVA在线判题系统:译文提交与自动化工具源码分享

UVA(UVa Online Judge),是一个广受欢迎的在线编程题库及判题系统,为全球编程爱好者提供了一个测试和提升编程能力的平台。它不仅支持超过上千道各类编程题目的在线提交和即时判题,而且还具备社交和学习的功能,使得用户可以在解决实际问题的同时进行编程技能的提高和知识的分享。版本控制系统是一种记录文件变化历史的工具,它能够追踪到每次提交的更改。版本控制是软件开发中的基本要求,它不仅可以帮助我们管理代码,还可以回滚到之前的版本,或者在多人协作的情况下避免代码冲突。

weixin_35706067的博客 932

UVa Online Judge的重建

摘要:2018年7月获悉UVaOJ创始人Miguel Ángel Revilla教授去世,其平台陷入无人管理状态。其子Miguel Revilla Rodriguez试图维护父亲的遗产,但因平台老旧(基于2005年的Joomla)决定开发开源新平台。新平台OnlineJudge已更换域名和Logo,移除大学相关标识,目前处于开发阶段。项目开源在GitHub,作者详细记录了在Ubuntu虚拟机中编译运行该项目的步骤。文章呼吁支持Miguel的工作,可通过捐赠方式资助项目开发。

寂静山林 2680

uva.onlinejudge.org:时间通过 UVA 挑战

uva.onlinejudge.org

UVa Online Judge部分题目代码

这里面全部为在Uva Online Judge上面的部分题目的解答,里面提供了解答使用的源代码。

UVa在线审判系统:一个为编程竞赛而生的平台

UVa在线审判系统:一个为编程竞赛而生的平台 去发现同类优质开源项目:https://gitcode.com/ 如果你是一位热衷于编程竞赛的人,那么 UVa 在线审判系统(UVa Online Judge)可能会成为你的新宠。作为一个基于互联网的编程竞赛平台,它提供了大量的问题集、实时反馈功能和多种编程语言支持。 项目简介 UVa 在线审判系统是一个免费的开源项目,由来自世界各地的志愿者维护和更新...

gitblog_00040的博客 1685

UVa-online-judge:针对在http://uva.onlinejudge.org上发现的一些问题的解决方案的集合

UVa-online-judge:针对在http://uva.onlinejudge.org上发现的一些问题的解决方案的集合

UVa 工具网站

uva 工具网站 顶 顶!!! UVa Online Judge 工具網站 转自http://www.csie.ntnu.edu.tw/~u91029/uva.html Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 Mirror這個站專門提供UVa Online Judge中譯題目。非常棒!非常棒!非常棒!我在搜尋引擎輸入過上百次的Luck

GooMaple 5910

UR机械臂正逆运动学解析:从DH参数到8组解的完整求解策略

本文深入解析UR机械臂的正逆运动学求解策略,从DH参数原理到完整的8组解求解方法。详细介绍了正运动学的坐标变换过程,以及逆运动学中Atan2函数和三角恒等变换的应用,并揭示了8组解的产生机制。通过实际案例和调试技巧,帮助工程师掌握UR机械臂运动学求解的核心技术。

weixin_29094775的博客 412

复旦微FMQL45T900平台RGMII网口调试实战:从PHY寄存器读取异常到链路建立

本文详细记录了复旦微FMQL45T900平台RGMII网口调试的全过程,重点解决了PHY寄存器读取异常问题。通过电压配置调整、时序优化和硬件信号完整性检查,最终成功建立网络链路。文章提供了实用的调试经验和解决方案,适合嵌入式开发人员参考。

weixin_29193359的博客 287

UVa12532 - Interval Product(Fenwick树)

#include #include using namespace std; const int N = 100010; struct Fenwick { private: vector fw; public: int lowbit(int n) { return n & (-n); } void init(int n) { fw.assign(n + 1,

多看多听多总结 902

Docker部署FRP实现内网穿透

FRP是一款开源内网穿透工具,通过在公网服务器部署服务端(FRPS),内网设备运行客户端(FRPC)实现外部访问。支持TCP、UDP、HTTP等多种协议。部署时需配置服务端(如群晖NAS使用Docker)和客户端(如Windows下载可执行文件)。服务端需设置监听端口、控制面板及Token认证,客户端需指定服务器地址和相同Token。完成配置后可通过公网IP或域名访问内网资源,并在控制面板监控连接状态。

波哥技术栈 1598

UVa12532 - Interval Product(线段树)

主要用到线段树,涉及到创建,点

多看多听多总结 689

面试中常考的数学题——截木棍、圆上取点、赛马、红蓝墨水,测试毒药、坐到正确座位问题

文章目录1.将一根木棒截成三段,问能够组成三角形的概率;2.在圆上任取三点,问能够组成锐角、直角、钝角三角形的概率;3.共有25匹马,找出最快的3匹,只有5个赛道,每次比赛只能得到5匹马的速度排序,最少需要多少次比赛;4 有两瓶红蓝墨水,体积一样,现在从红墨水中舀一勺加入蓝墨水中,搅拌均匀后,在从蓝墨水中舀一勺加到红墨水中,试问这两瓶墨水哪瓶纯度更高。 1.将一根木棒截成三段,问能够组成三角形的概率; 来源:https://blog.youkuaiyun.com/weixin_41245919/article/deta

weixin_41558411的博客 4904

智能体在车联网中的应用:一份详尽到每日的100天学习路线图

这100天的旅程,是一次对毅力、学习方法和工程实践能力的综合考验。它不仅关乎掌握一系列技术点,更关乎培养解决复杂系统性问题的思维模式——将宏观的交通需求分解为微观的智能体决策,再通过多智能体协同涌现出宏观的智能行为。当你完成这份大纲时,你将拥有的不仅是一个项目作品集,更是一套应对“智能体+车联网”乃至更广泛AI+垂直领域挑战的方法论。未来已来,期待你成为构建智能交通新生态的关键贡献者。

IT深耕十余载,大道之简 1330

UVa Online Judge参考程序集合

一下为本人在UVa Online Judge系统正确提交的代码,附上一定的解释,以次给广大编程爱好者作为参考~~

MyLinChi的博客 1487

uva 工具网站 顶 顶!!!

Online Judge System 源起 「Association for Computing Machinery (ACM) 」是一個致力於電腦科學教育的協會,出版大量專業期刊、文獻,舉辦重大的計算機科學會議,在資訊界舉足輕重、名聞遐邇。 ACM 每年度都會舉辦一次「The ACM-ICPC International Collegiate Programming Contest (A

Kizuki 3691

【电子通识】TINA-TI怎么使用受控源向导创建受控源

TINA-TI怎么使用受控源向导创建受控源

一点硬件 357

Vue - 简约大气 404 页面

效果图 实现代码 复制即可。 <template> <div> <div class="error"> <!-- 图片可保存到本地 --> <img src="https://img-blog.csdnimg.cn/20210715111039922.png"> <p>抱歉!你访问的页面不存在或已删除 :( </p> <span class="back" @click="go(

🏆 前端领域优质创作者 3369

UVa online judge Score

受作者蛊惑,尝试了一波UVa,按作者的说法,这些习题大部分都是看题都能解决的,只有一小部分需要点灵感。然而才做几题,我就感觉磕磕绊绊(证明我太菜了),话不多说,上题。Q: There is an objective test result such as “OOXXOXXOOO”. An ‘O’ means a correct answer of a problem and an `X’ mean...

ExNexus的博客 632

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

通过vjudge刷Uva的题目(解决Uva网站打开慢的问题)

最近在跟着算法竞赛入门经典刷题,发现Uva网站打开超级慢,进个主页面都需要好几秒。后来发现可以通过vjudge网站刷Uva的题目,很是方便,在这mark一下,顺便做一下推荐。 vjudge网址:https://vjudge.net,点击后会进入vjudge网站主页,如下图: 可以发现vjudge支持包括POJ、Uva、ZOJ等等一系列OJ网站的题目评测。第一次通过该网站刷题需要先注册一个账...

日沉云起的博客 2万+

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

下面是几个比较大的在线提交系统(Online Judge)

下面是几个比较大的在线提交系统(Online Judge) 浙江大学 Online Judge(ZOJ)http://acm.zju.edu.cn国内最早也是最有名气的OJ,有很多高手在上面做题。特点是数据比较刁钻,经常会有你想不到的边界数据,很能考验思维的全面性。 北京大学 Online Judge(POJ)http://acm.pku.edu.cn/JudgeOnline/建立较晚,但题目...

weixin_33744854的博客 923

UVa Online Judge - Volume I 题目和解答索引

  UVa Online Judge - Volume I 题目和解答索引。前面为原题链接,后面为我的解答链接。 返回总目录  100 - The 3n + 1 problemAd hocSolution101 - The Blocks ProblemSimulationSolution102 - Ecological

程序道 4773
上一篇: Codeforces Round #200 (Div. 2) C. Rational Resistance(脑洞思维)
下一篇: Codeforces Round #200 (Div. 2)D. Alternating Current (堆栈)
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值