hdu 1698 Just a Hook (线段树区间更新裸题)

SAP面试全过程(已拿offer) 周五打电话给我说过了SAP第一轮面试,第二轮要在下周四北京,这几天终于体会到了什么叫做重压下的感觉,越复习越虚,看别人的面经都感觉卧槽这问题也巨难了吧...连去北京可以见妹子这种事情都感觉一点心情都没有。面前准备固然是要有的,但关键是平时就要有料,多想想自己做的项目。当作一个给自己的提醒吧! 阅读详情

Just a Hook

                                                  Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
                                                                      Total Submission(s): 22774    Accepted Submission(s): 11390



Problem Description
In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length.



Now Pudge wants to do some operations on the hook.

Let us number the consecutive metallic sticks of the hook from 1 to N. For each operation, Pudge can change the consecutive metallic sticks, numbered from X to Y, into cupreous sticks, silver sticks or golden sticks.
The total value of the hook is calculated as the sum of values of N metallic sticks. More precisely, the value for each kind of stick is calculated as follows:

For each cupreous stick, the value is 1.
For each silver stick, the value is 2.
For each golden stick, the value is 3.

Pudge wants to know the total value of the hook after performing the operations.
You may consider the original hook is made up of cupreous sticks.
 

Input
The input consists of several test cases. The first line of the input is the number of the cases. There are no more than 10 cases.
For each case, the first line contains an integer N, 1<=N<=100,000, which is the number of the sticks of Pudge’s meat hook and the second line contains an integer Q, 0<=Q<=100,000, which is the number of the operations.
Next Q lines, each line contains three integers X, Y, 1<=X<=Y<=N, Z, 1<=Z<=3, which defines an operation: change the sticks numbered from X to Y into the metal kind Z, where Z=1 represents the cupreous kind, Z=2 represents the silver kind and Z=3 represents the golden kind.
 

Output
For each case, print a number in a line representing the total value of the hook after the operations. Use the format in the example.
 

Sample Input
1 10 2 1 5 2 5 9 3
 

Sample Output
Case 1: The total value of the hook is 24.

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698

题目大意:初始化数组为1,每次更新区间X到Y的值为Z,最后求和。线段树区间更新。

代码如下:

#include <cstdio>
#include <cstring>
const int maxn=400005;
int tr[maxn],nd[maxn];
int a,b,c;
void pushdown(int len,int root) //重要函数,更新区间里的tr值
{
	if(nd[root])  
	{
		nd[root*2]=nd[root*2+1]=nd[root];
		tr[root*2]=(len-len/2)*nd[root];
		tr[root*2+1]=(len/2)*nd[root];
		nd[root]=0;
	}
}
void Query(int l,int r,int root)
{
	if(r<a||l>b)
		return;
	if(l>=a&&r<=b)
	{
		nd[root]=c;
		tr[root]=(r-l+1)*c;
		return;
	}
	pushdown(r-l+1,root);
	int mid=(l+r)/2;
	if(a<=mid)
		Query(l,mid,root*2);
	if(b>mid)
		Query(mid+1,r,root*2+1);
	tr[root]=tr[root*2]+tr[root*2+1];
}
int main(void)
{
	int t;
	scanf("%d",&t);
	for(int ca=1;ca<=t;ca++)
	{
		int n,m;
		scanf("%d%d",&n,&m);
		memset(nd,0,sizeof(nd));
		for(int i=0;i<4*n;i++)
			tr[i]=1;
		for(int i=0;i<m;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			Query(1,n,1);
		}
		printf("Case %d: The total value of the hook is %d.\n",ca,tr[1]);
	}
}


ML307R OpenCPU TCP使用 实现现象 平台下发数据,板子在收到数据之后,马上再发送到平台,通过串口助手可以看到已经接收到数据。ML307R TCP 是使用LWIP的标准的socket通信,具体TCP流程可以自行百度。实验目的:实现把接收的数据再发送到服务端。因为是4G,所以必须用外网的。 阅读详情

相关推荐

如何在离线的电脑上部署一个本地Deepseek(使用ollama)

例如,如果您的显卡显存为 16GB,官方推荐使用 32b 大小的 DeepSeek 模型。请根据您的硬件配置选择适合的模型版本,以获得最佳性能。首先我们需要将ollama和chatbox的安装包,Deepseek模型文件通过U盘或者光盘的形式导入到这台不能联网的电脑上。按照时间排序,找到最大的那个文件,就是gguf格式的模型,复制出来,改名为qwen2.5-coder0.5b.gguf。:基于开源模型(如 QWEN 和 LLAMA)微调,参数量从 1.5B 到 70B 不等,适合本地硬件部署。

qq_41854911的博客 1万+

uva1232 la4108 skyline (线段树区间更新,维护最值)

原题链接 十分明显的一道线段树裸题,但是细节操作比较多,卡了1小时,0.0蒟蒻表示很难受。 根本的解决方法就是线段树的区间更新和维护最值。看了其他大神的博客有的还维护的了一个区间最小值来优化时间,但是仔细一想其实不必要。记录maxv[]和col[](懒惰标记)即可。 详细代码: #include #include #include #include

wzgcrc的博客 385

单片机NTC热敏电阻测温:六种实用电路方案与选型指南

本文详细介绍了单片机系统中NTC热敏电阻测温的六种实用电路方案,包括分压法、恒流源法、RC充放电法、电桥法、频率法及集成专用IC方案,并提供了关键的硬件选型指南和软件处理技巧,帮助工程师实现高精度、低成本的温度测量。

herb5的博客 832

【题解】Just a Hook HDU - 1698(线段树 区间更新)⭐⭐⭐

Just a Hook HDU - 1698 In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the s...

Suprit's blog 701

Windows如何使用Anaconda 3进行keras环境的配置

** Windows如何使用Anaconda 3进行keras环境的配置 搭建Keras环境* Anaconda3如何安装keras,主要包括下面三步: 1.安装mingw libpython 2.安装theano 3.安装keras 若你还没有按装anaconda,赶紧下载安装吧! 下载途径有两个 (1)Anaconda版本为Anaconda 4.4.0,对应的python版本为3.6,附上An...

Lance_liangliang的博客 1606

别再只仿真原理图了!用ADS做微带功分器,版图仿真这一步才是关键

本文深入探讨了使用ADS进行微带功分器设计时版图仿真的重要性,指出原理图仿真与版图仿真的本质差异及其对性能的影响。通过详细分析版图效应、关键设置和优化策略,帮助工程师避免常见陷阱,提升设计效率和准确性。文章特别强调了版图仿真在确保微波电路性能中的关键作用。

weixin_42561476的博客 416

【HDU 1698 --- Just a Hook】线段树水题

【HDU 1698 --- Just a Hook】线段树水题 题目来源:点击进入【HDU 1698 — Just a Hook】 Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the sam

来日浅谈的博客 636

【Claude Code】Unable to connect to API 报错原因与排查解决全流程

深入分析 Claude Code 中 Unable to connect to API 系列报错的根因,涵盖 ECONNREFUSED、ECONNRESET、ETIMEDOUT 等 6 种变体,提供从网络连通性检测、代理配置到 LLM 网关路由的完整排查路径,帮助开发者快速恢复 Claude Code 的正常使用。

多媒体编程、网络编程、系统编程、网络安全编程、驱动编程 2862

HDU 1698 Just a Hook(线段树区间修改)

题目链接:点击打开链接 题意: 输入一个n表示一段长度为n的区间,有n个编号为1~n的点,初始值全部为1。 有q个操作, 每个操作有3个数:l,r,v表示将区间l~r的所有元素修改为v。 求经过q次修改后的整个区间的值之和。 该题是最典型的线段树区间修改问题, 需要用到所谓的懒惰标记。   听起来挺难的,其实非常简单, 其原理如下: 因为修改很多值, 如果还是按照原来的更新方法, 每个结点

AC_Arthur的专栏 4608

CANoe中如何仿真报文的CRC和Counter,告诉你三种方法皆可实现

CANoe中如何仿真报文的CRC和Counter

蚂蚁小兵 5293

元宇宙通证- 九、IT/ICT发展史全景长图

九、IT/ICT发展史全景长图 (一)综述 IT是Information Technology的缩写,意为”信息技术“,包含现代计算机、网络、通信等信息领域技术。自1844年人类历史上发出来第一份电报,实现了信息的长图传输,信息技术发展的历史大幕随之拉开。信息技术的普遍应用,是进入信息社会的标志。 IT技术最早发源于半导体,然后发展处计算机、通信网和互联网,进而演进到现在的AI、XR、计算机、大数据、物联网、工业互联网、区块链、量子计算等。 有人说元宇宙是下一代互联网,有人说元宇宙是互联网的终极形态。 我们

沧海之巅的专栏 1万+

HDU-1698 Just a Hook(线段树模板,懒标记区间修改)

HDU-1698 Just a Hook /* * HDU-1698 Just a Hook * http://acm.hdu.edu.cn/showproblem.php?pid=1698 */ #include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <queue> using namespace std; const

NaNa 170

C/C++ 静态代码检查工具cppCheck

Cppcheck是一个用于C/C++代码的静态分析工具,它可以帮助开发者检测代码中的错误;Cppcheck可以检测出许多类型的错误,包括语法错误、未使用的函数、内存泄漏、未初始化的变量等;Cppcheck还支持用户自定义规则,这使得开发者可以根据自己的需求定制Cppcheck的行为;使用--suppress如果你想要忽略某些警告,可以在命令行中使用 --suppress 选项。

贝勒里恩的博客 4962

hyu 1698 Just a Hook

hdu1698 Just a Hook 题目其实是比较基础的线段树区间更新题。然后要注意的是,make树的时候,lazy tag要记得归0(因为个人习惯是在初始化的时候直接把lazy tag=0初始化,因此,如果有多组数据,只是这样做而不在make的时候进行初始化就会有错误。) #include <bits/stdc++.h> using namespace std; usin...

qq_33843297的博客 174

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

[HDU 1698]Just a Hook[线段树区间更新]

题目链接:[HDU 1698]Just a Hook[线段树区间更新] 题意分析: 屠夫的钩子被分割成n个节,每节初始时都有铜制,铜制每节价值为1.然后给出q个操作,改变段l,r的材料为其它材料。最终询问:此时钩子的总价值是多少? 解题思路: 线段树的区间更新。使用到了lazy思想,也就是代码中的add数组。 整个原理就是,更新的时候,当某段被包含在被更新区间内时,只需给该段标记一下改变

闲停 676

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

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

hdu1698 Just a Hook 线段树【区间更新】

题目链接在这里 题目描述: 在[1, n]区间有金属棍,棍的材料有三种,每种有不同的价值。 现在有q种操作,每种操作有x y z三个数,意思是[ x,  y ]区间上的金属棍的价值置为z。求q次更新之后,整个区间的总价值是多少。 思路分析: 这是个区间更新操作,如果用暴力更新的方法肯定会超时,所以考虑用线段树。 代码如下: #include &lt;cstdio&gt; #incl...

Joel 256

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Just a Hook(HDU-1698线段树代码讲解很详细)

Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length. Now Pudge wants to do some operations on the ho

weixin_44313771的博客 2756

HDU1698-Just a Hook(线段树 区间更新 lazy标记)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of seve...

QAQ 223

hdu1698-Just a Hook (线段树区间更新)(延迟标记)

Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 32616    Accepted Submission(s): 15997 Problem Description In the game

wangheng 468

Just a Hook HDU - 1698(线段树区间更新)

题意就是给你一段长度n,和q个操作,每次操作把一个区间全部更新成1 || 2 || 3 一个线段树lazy数组就够了 思路,写一个下推函数,一个更新函数,一个查询函数,查询函数就是最后查询区间和 //#if 0 #include <map> #include <stack> #include <queue> #include <vector> #...

仰望蓝天的博客 691

hdu 1698 Just a Hook

http://acm.hdu.edu.cn/showproblem.php?pid=1698 Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 21917    Accepted Submission(s)

大太阳 738

HDU 1698 Just a Hook(线段树区间更新)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 注意这个题目要输出的结果是整个区间的,因此不需要query函数,直接输出1节点的值。 #include #include using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define root 1

536

hdu 1698 Just a Hook 线段树区间更新

Just a Hook                                                                   Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description In the

yu_ming_cong的专栏 319

HDU 1698 Just a Hook 线段树区间更新

经过昨天六个单点更新线段树水题的洗礼,今天上手快了很多。这道题也是一个线段树的一个入门题 这个题是对一个区间段内的数进行整体的更新,如果对区间的更新还是最终落实到对点的更新,显然复杂度是很高的,因此在处理上需要换一种方式 这次,线段树节点存的内容是其左右子树的颜色信息,如果左右子树颜色相同,那么他的值就是左右子树的颜色值,如果不同,则标记为-1 本题的重心在于update时的处理,如果(L=

renew 870

成段改A为B更新区间求和 hdu 1698 Just a Hook

题目链接   hdu 1698 Just a Hook   题目大意:给你n个数(初始时每个数的值为1),m个操作,每个操作把区间[l,r]里的数更新为c,问最后这n个数的和是多少。   解题思路:O(-1) #include #include using namespace std; const int maxn=100005; int tree[4*maxn]; int

ACM_10000h的专栏 578

【线段树区间更新】hdu1698 Just a Hook

【线段树区间更新】hdu1698 Just a Hook In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same l

xuziling_的博客 233
上一篇: hdu 2795 Billboard(线段树单点更新)
下一篇: Codeforces Round #105 (Div. 2) C. Terse princess
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值