hdu 1698 Just a Hook 线段树求解

ThingsBoard入门实战(二):ThingsBoard 设备接入 文章目录ThingsBoard 设备接入一、设备配置/设备类型二、设备三、设备接入HTTPCOAPMQTT四、下一步 ThingsBoard 设备接入 设备接入并不一定需要真正的设备,我们可以通过程序。或者命令来模拟设备,向平台发送信息。 这节我们先为用户分配一个设备,然后通过模拟设备命令更新设备的状态(遥测值)。 一、设备配置/设备类型 添加一个叫"路灯"的设备配置。 设备配置听起来比较抽象,可以认为是设备类型或者是设备类型的配置。实际上,ThingsBoard 中很多时候让选择设备类型,就是选的这个。 阅读详情

Just a Hook

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

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.

题意:有 t 组测试数据,n 为钩子长度(1<=n<=100000),m 为操作的次数。初始时,每个钩子的价值为1,操作由三个数字组成x,y,z表示把区间[x,y]的钩子变成的价值变成z(1代表铜,2银,3金)。

使用 lazy 懒惰标记来节省时间

注意:建树部分

void build_tree(int id,int l,int r)
{
tree[id].lazy=0; //      因为要多次建树,所以初始化时不能仅仅更新叶节点的lazy 要将lazy全部清零
if (l>=r)
{
tree[id].val=1;
return;
}

int mid=(l+r)/2;
build_tree(lson,l,mid);
build_tree(rson,mid+1,r);
push_up(id);
return ;
}
另外,注意输入输出格式

具体代码实现:
#include<iostream>
#include<algorithm>
#include<stdio.h>
#define lson (id*2)
#define rson (id*2+1)
using namespace std;
struct edge{
int val;
int lazy;
}tree[800005];
int n,ans=0,m,t;
void push_up(int id)
{
tree[id].val=tree[lson].val+tree[rson].val;
return ;
}
void push_down(int id,int l,int r)
{
int mid=(l+r)/2;
if (tree[id].lazy==0) return ;
tree[lson].val=tree[id].lazy*(mid-l+1);
tree[rson].val=tree[id].lazy*(r-mid);
tree[lson].lazy=tree[id].lazy;
tree[rson].lazy=tree[id].lazy;
tree[id].lazy=0;
return ;
}
void build_tree(int id,int l,int r)
{
tree[id].lazy=0;
if (l>=r)
{
tree[id].val=1;
return;
}
int mid=(l+r)/2;
build_tree(lson,l,mid);
build_tree(rson,mid+1,r);
push_up(id);
return ;
}
void add_tree(int id,int l,int r,int L,int R,int v)
{
if (l>=L&&r<=R)
{
tree[id].val=(r-l+1)*v;
tree[id].lazy=v;
return ;
}
int mid=(l+r)/2;
push_down(id,l,r);
if (mid>=L)
add_tree(lson,l,mid,L,R,v);
if (mid+1<=R)
add_tree(rson,mid+1,r,L,R,v);
push_up(id);
return ;
}
void query_tree(int id,int l,int r,int L,int R)
{
if (l>=L&&r<=R)
{
ans+=tree[id].val;
return ;
}
int mid=(l+r)/2;
push_down(id,l,r);

if (mid>=L) query_tree(lson,l,mid,L,R);
if (mid+1<=R) query_tree(rson,mid+1,r,L,R);

push_up(id);
return ;
}
int main()
{
cin>>t;
int num=0;
while(num<t)
{
num++;
scanf("%d",&n);
build_tree(1,1,n);
scanf("%d",&m);
for (int i=1;i<=m;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
add_tree(1,1,n,a,b,c);
}
cout<<"Case "<<num<<": The total value of the hook is "<<tree[1].val<<"."<<endl;
}
}
Verilog基础知识11(异步FIFO为什么使用格雷码(gray-code) ) 需求说明:Verilog设计 内容       :第一部分 异步FIFO为什么使用格雷码                   第二部分 格雷码在异步FIFO中的使用 来自       :时间的诗 第一部分 异步FIFO为什么使用格雷码 原文:http://www.cnblogs.com/kxk_kxk/p/3931591.html 异步FIFO通 阅读详情

相关推荐

先进封装技术 Part03---重布线层(RDL)的科普

RDL是一种在芯片封装过程中用于重新分布电气连接的技术。它通过在芯片表面或中介层上形成额外的布线层,重新分配芯片的I/O(输入/输出)位置,以适应不同的封装需求和提高电气连接的灵活性。

阿拉伯梳子的专栏 4736

区间染色——kuagnbin线段树专题(3)

本来是把区间染色放到第一次总结的,但是后来才发现自己对区间染色并没有那么熟练,所以特意提取出来总结一遍。 区间染色的查询主要有两种:一种是直接询问[L,R]之间的颜色种类,还有就是对每个颜色有一定的权值,求[L,R]之前的权值和 HDU 1698 Just a Hook P2161 [SHOI2009]会场预约 第一道题就是根据颜色的权值求区间和,第二种就是询问颜色种类个数 写第一道题的时候几乎是...

qq_37087993的博客 354

液晶电视维修必看:TCON逻辑板故障排查全指南(附常见问题解决方案)

本文详细解析了液晶电视TCON逻辑板的工作原理与故障排查方法,涵盖LVDS信号处理、DC-DC电压系统等核心知识。提供从基础测量到高级维修的完整指南,帮助技术人员快速诊断黑屏、竖线等常见故障,并给出预防性维护建议,提升维修效率与成功率。

weixin_42535461的博客 630

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

告别迷茫!手把手教你用Altova XMLSpy编写EtherCAT从站ESI文件(附避坑指南)

本文详细介绍了如何使用Altova XMLSpy高效编写EtherCAT从站ESI文件,涵盖核心架构、通信通道配置、过程数据映射等关键步骤,并提供了常见问题排查与性能优化建议。通过实战案例和避坑指南,帮助工程师快速掌握EtherCAT从站开发技巧,提升工作效率。

weixin_42570484的博客 401

SystemVerilog学习总结

因为选择的offer是IC验证,以前学的是设计,所以只能再学systemverilog(SV)和UVM了。在学习SV和UVM之前,我认为需要学习以下几个部分:数字电路、c++和verilog。因为IC验证确实有不少别的专业之前没学过数字电路和Verilog,所以还是最好先学习一下。 知识点的总结主要是通过systemverilog验证-测试平台编写指南这本书进行的,所以请看书。通过对这本书的目录进行重点的划分,然后再进行相关知识点的总结。最后,给出自己收集的别的博主IC EDA环境的虚拟机,以及使用虚拟机需

博主毕竟还是人,肯定会有错误,各位看的时候发现错误提出来就好 1万+

[kuangbin带你飞]专题七 线段树E - Just a Hook HDU - 1698

E - Just a Hook HDU - 1698 #include<bits/stdc++.h> using namespace std; const int M = 100000+100; int st[M<<2],lazy[M<<2]; void pushdown(int l,int r,int rt) { if(lazy[rt]) { ...

bjfu170203101的博客 270

mbed驱动st7789屏幕-硬件选择及连接(1)

在单片机项目中,交互性至关重要,而视觉感知是用户交互的直接体现。本期专栏介绍了如何使用mbed平台驱动ST7789型号的TFT屏幕,以显示字符、汉字和图像。由于针对STM32L432KC的mbed驱动库尚未完整,作者自行编写了一个基于mbed的ST7789屏幕驱动库,并将在专栏中提供全代码及使用指南。

weixin_64524066的博客 392

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

热红外图像小目标检测算法综述

热红外小目标检测算法综述,着重介绍基于深度学习的小目标检测算法

Littro Innovations 4251

android studio 2022打开了v1 签名但是生成的apk没有v1签名问题

我使用了Android Studio Flamingo | 2022.2.1 Patch 2版本的IDE编译了一个apk,但是apksigner查看apk的签名信息时,发现只有v2签名,没有v1签名。试着改小一下minSdkVersion 为23重新编译apk,再检测一下签名版本v1居然打开了!参考网上搜索到的方法,手动在build.gradle里面添加。但是编译出来的apk还是只有v2的签名。里面提到了v1签名还和。

hedalei的博客 470

【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

R语言机器学习算法实战系列(十三)随机森林生存分析构建预后模型 (Random Survival Forest)

本教程运用随机森林生存分析筛选与患者生存状态显著相关特征。该方法借随机森林这一强大机器学习算法,构建多棵决策树并集成结果,以提高生存分析准确性,识别关键生物标志物。接着,利用选定特征构建风险得分,将多个特征转化为单一数值,量化患者风险水平。之后,依据风险得分将患者分为高、低风险亚型,为临床治疗提供个性化指导。最后,通过分析时间依赖的 ROC 曲线评估模型长期预测能力。此曲线计算不同阈值下的真正例率与假正例率,在多个时间点评估,全面展现模型长期稳定性与准确性。

专注生信领域 2039

【题解】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

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

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

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

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

【线段树】HDU 1698 Just a Hook

线段树 建树(pushup向上求和或者其他操作),是一个递归过程。tree[ ]要开4倍数组。为什么呢?其实2^x<=N<2^(x+1)个叶子,我们会有一个等比数列,N+N/2+N/3+...=(2^(x+1)-1)=2*2^x-1<=2*N-1<2*N,也就是最多有2N个结点,但是为什么开4倍数组?虽然我们只有2N个叶子,但是我们不能确定它们的标号是前2N个。而且我们...

L_X_ 199

HDU1698-Just a Hook

http://acm.hdu.edu.cn/showproblem.php?pid=1698 #include<cstdio> #include<algorithm> #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 using namespace std; const int ma...

weixin_30300225的博客 162

【线段树】 hdu1698 Just a Hook

Just a Hook 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

Ted's 游乐园 2284

线段树 Just a hook

怎么说。。暑假集训的数据结构,包括线段树。。然后到现在线段树很久没敲了,结果武汉校赛一道线段树没写出来坑了队友。。然后。。重新复习一遍吧。。线段树的代码风格也定下来了。。 E - Just a Hook  HDU - 1698  #include using namespace std; const int MAXN=100005; #define lson k<<1

ontrmhsis 405

【线段树区间更新】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 1698 Just a Hook

题目链接:Problem - 1698 (hdu.edu.cn) 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 o.

m0_55682843的博客 221

E - Just a Hook HDU 1698 (线段树+类似延迟标记)

E - Just a Hook Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Practice Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing

qwesde 669

【HDU 1698】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 length. Now ...

词庸 1309

HDU 1698 Just a Hook 线段树

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

窦小雨的小点子 312

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

HDU1698 Just a Hook 线段树成段替换

传送门:HDU1698 题意:给定n和q个操作,每个操作为:i  j  k  令num[t]=k(i 思路:数据量较大,暴力肯定不行。考虑用线段树进行区间替换,这里询问只有一次,且是询问总区间,所以可以直接输出一号节点的信息。 代码:#include #include #include #include #include #include #include #include #include

WA是一笔财富 281
上一篇: sgu 128
下一篇: POJ 2828 Buy Tickets 题意&题解&代码(c++)
deritt
博客等级 码龄11年 21粉丝 150原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值