【hdu】1698 just a hook 中文题意&题解

【UOJ170】Picks loves segment tree VIII 【题目链接】 点击打开链接 【前置阅读】 【BZOJ4695】最假女选手 【BZOJ3064】【TYVJ1518】CPU监控【UOJ169】【UR #11】元旦老人与数列 【思路要点】 前置阅读中的前两题中,我们分别对线段树的区间取最大/最小值和线段树的历史最大/最小值进行了研究。本题中,两类问题同时出现,因此我们 阅读详情

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.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.

题意:给一个序列,初始值都是1,有多组测试数据,每个数据序列长度为n,有m个操作,每个操作给出x,y,c,表示把[x,y]区间的值改为c,最后询问序列总和
输出格式为:
Case_1:_The_total_value_of_the_hook_is_num
下划线是空格

题解:很明显的线段树,为了省时间,修改操作应该用lazy标记,表示某个区间的值都被改为lazy,树的细节很多,详见代码

push_up函数是统计子叶的值总和
push_down函数是把lazy值传递给子叶
build函数是初始化
注意任何时候tre[id].v都表示区间的值之和

代码如下
:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#define lson id*2
#define rson id*2+1
#define yy int mid=(l+r)/2
using namespace std;
struct node{int v;int lazy;} tre[900000];
inline void push_up(int id)
{
        tre[id].v=tre[lson].v+tre[rson].v;return ;
}
inline void push_down(int id,int l,int r)
{
        if (l>r) return ;
        if (tre[id].lazy==0)    return ;
        yy;
        tre[lson].lazy=tre[id].lazy;
        tre[rson].lazy=tre[id].lazy;
        tre[lson].v=tre[lson].lazy*(mid+1-l);
        tre[rson].v=tre[rson].lazy*(r-mid);
        tre[id].lazy=0;
        return ;
}
int ans;
inline void add(int id,int l,int r,int L,int R,int val)
{
        if (l>r || L>R) return ;
        if (l>=L && r<=R)
        {
                tre[id].lazy=val;
                tre[id].v=val*(r-l+1);
                return ;
        }
        yy;
        push_down(id,l,r);
        if (L<=mid)     add(lson,l,mid,L,R,val);
        if (R>=mid+1)   add(rson,mid+1,r,L,R,val);
        push_up(id);

}
inline void que(int id,int l,int r,int L,int R)
{
        if (l>r || L>R) return ;
        if (l>=L && R>=r)
        {
                ans+=tre[id].v;
                return ;
        }
        yy;
        push_down(id,l,r);
        if (L<=mid)     que(lson,l,mid,L,R);
        if (R>=mid+1)   que(rson,mid+1,r,L,R);
        push_up(id);
        return;

}



inline void build(int id,int l,int r)
{
        if (l>r) return ;
        if (l==r)       {tre[id].lazy=0;tre[id].v=1;return ;}
        yy;
        tre[id].lazy=0;
        build(lson,l,mid);
        build(rson,mid+1,r);
        push_up(id);
        return ;

}

int a,b,c,d,n,m,t;



int main()
{
cin>>t;
int num=0;
while(num<t)
{
num++;
scanf("%d",&n);

build(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(1,1,n,a,b,c);
}
cout<<"Case "<<num<<": The total value of the hook is "<<tre[1].v<<"."<<endl;
}
}

Dynamics 365 On-Premise Server v9.0部署体验 期盼已久的Dynamics 365 On-Premise的版本升级终于在11月初姗姗来迟。 11月2日起已经可以在官方渠道下载正式版的Dynamics 365 Server v9.0安装文件,版本号9.0.2,随手附上中文版安装文件下载地址。 想必已经有不少小伙伴开始尝试各种升级、安装了吧。 Dynamics 365 On-Premise的安装过程,度娘一下已经有很多了,这里就不赘述了,只是... 阅读详情

相关推荐

Kimi K3大模型API实战:从调用到本地知识库问答系统构建

大语言模型(LLM)作为人工智能的核心技术,通过海量数据训练获得理解和生成自然语言的能力。其工作原理基于Transformer架构,通过自注意力机制捕捉长距离依赖关系。这项技术的核心价值在于能够将非结构化文本转化为可计算、可交互的智能体,极大地提升了信息处理和自动化任务的效率。在应用场景上,大模型广泛应用于智能对话、代码生成、文档总结与问答等领域。其中,国产大模型如月之暗面推出的Kimi K3,凭借其在**长文本处理**和**中文场景优化**方面的优势,为开发者提供了新的技术选项。本文将以Kimi K3为例

weixin_30694389的博客 306

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 Pud...

李!的博客 814

手把手教你用稚晖君Dummy机械臂实现位置控制:代码解析与调试技巧

本文深入解析了稚晖君Dummy机械臂实现高精度位置控制的代码核心与调试技巧。从CAN总线通信协议、三种位置控制模式(基础、带时间约束、带速度限制)的解析入手,详细阐述了命令帧结构、状态同步机制及单位换算。文章还提供了从通信测试、PID参数整定到异常处理、性能优化的完整实战调试流程,并探讨了多轴协调、自适应控制等进阶话题,旨在帮助开发者快速掌握该机械臂的精准运动控制。

weixin_29164091的博客 423

hdu1698(线段树区间更新)

题目链接:http://hdu.hustoj.com/showproblem.php?pid=1698 题意:没啥好说的,读题吧(;¬_¬) 思路:典型的线段树区间更新 代码: 1 #include&lt;iostream&gt; 2 using namespace std; 3 4 const int maxn = 1e5 + 10; 5 stru...

dgbxssz959266的博客 210

普罗米修斯监控达梦数据库集群

-----------------------------------新增文件---------------------------------------注:图上即为启动成功,如果没有问题,则使用nohup后台启动程序。官网地址:https://github.com/gy297879328/dameng_exporter。注:prometheus的对数据库的指标采集如果高于60s一次,请手动修改提供表盘中的计算值。修改dameng_exporter.config配置文件,修改账号密码的部分。

weixin_49985403的博客 1691

【AUTOSAR-COM】Transmission Mode 和 Transfer Property

1.COM模块的基本概念 首先在描述Transmission Mode 和 Transfer Property之前,有必要对COM模块的基本处理有一个直观的理解,我所描述的和对概念理解的也不一定完全正确。 Signal:指的是通信协议中的,一条报文中所保存的若干信号。 I-PDU:至少在COM模块中,可以理解为一条报文。 上图是在CANdb软件中编辑一个报文的Layout的界面,可以很形象的将I-PDU对等为这里的一条Message,而Signal就是需要在Message中需要摆放的Signal

tim_hoven的博客 4645

CodeForces 490A Team Olympiad

题意: 编号为1、2、3的同学分成一组  问  最多形成多少组  并输出方案 思路: 模拟3个栈暴力 代码: #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef lon

House 1507

晶体管的 栅极gate 材料选用 多晶硅polysilicon,并采用 自对准工艺 self-aligned IC后端版图 【VLSI】

本文为了解决为什么要使用多晶硅作栅极触点的问题,先介绍了MOS管的工作原理是通过栅极上所加的电压控制漏极与源极之间电流,然后解释了栅极的材料为什么选用多晶硅,然后介绍了晶体管里栅极的自对准工艺(Self-Aligned Gate )。

Jie_MSD的博客 1万+

HDU1698(线段树区间更新求和)

题意是给你n长度的钩子,每单位的初始值为1,然后m个操作,将(l,r)之间的值变为v,求最后n长度的值的和。 #include #include #include #include #include #include #include #include #include #include #define LL __int64 using namespace std; con

慕枫幕影的专栏 1176

[捷稀 JCG Q30 Pro 刷机说明] 以刷入openwrt24.10为例

摘要: 本文详细介绍了捷稀JCG Q30 Pro路由器刷入OpenWrt 24.10系统的步骤。通过先刷入OpenWrt 23.05过渡固件,再升级Uboot,最后通过TFTP加载工厂镜像完成刷机。关键步骤包括解锁分区、刷写Uboot、进入恢复模式及配置网络。文章还提供了无线设置、Tailscale内网穿透等进阶命令,并附参考文档和固件下载链接。适用于有一定技术基础的玩家,需注意操作风险,严格按流程执行。

贤时间 7231

某音私信接口二进制解析

本文探讨了某音私信接口的二进制请求处理过程,重点分析了请求体中的非文本字符和混合编码结构。文章详细描述了编码过程,包括使用Protocol Buffers的序列化方法将结构化数据转换为字节流,并通过Uint8Array包装成二进制数组。作者展示了如何提取和补全s.encode方法,并将其转化为Base64字符串以便在Python中解码执行

码王吴彦祖的博客 906

Just a Hook(区间修改)

HDU 1689 题意:给定序列,默认值为1。m次操作,每次操作把区间 [x,y] 的值改为 z, 求操作完序列的和。 标签:区间修改 分析: 模板题,但是注意多组输入数据,每次要重置 lazy tag #include &lt;iostream&gt; #include &lt;cmath&gt; #include &lt;iomanip&gt; #include &lt;cstring&gt...

爱吃猫的鱼~ 461

鸿蒙录屏推流应用完整解决方案

本文介绍了鸿蒙录屏推流应用的完整解决方案。项目采用分层架构设计,包含录屏、编码、推流等功能模块,要求实现4小时稳定运行且延迟小于3秒。技术实现包括:1) 通过config.json配置应用权限和功能;2) 使用ScreenRecorderManager类管理录屏服务,实现视频采集、音频录制和编码参数配置;3) 核心功能包含初始化录屏器、开始/停止录屏等操作。该方案充分利用鸿蒙系统的多媒体API,实现了高性能的屏幕录制与实时推流功能。

huanghm88的专栏 296

HDU - 1698 - Just a Hook( 线段树 )

题目链接:点击进入 题目: 题意 给你一个长 n 的序列,初始值全为 1 ,q 次操作,每次将 [ x, y ] 的值改为 z ,问最后整个序列的和为多少 思路 线段树实现区间修改,以及根节点值查询 代码 //#pragma GCC optimize(3)//O3 //#pragma GCC optimize(2)//O2 #include&lt;iostream&gt; #include&lt;string&gt; #include&lt;map&gt; #include&lt;set&gt; //

Cosmic_Tree的博客 283

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

hdu1698(线段树/区间修改/求和)

hdu1698"Just a Hook" 题意: 有一个区间s [1,n],每一节si的初始价值为1。定义操作:x y val,将区间[x,y]中的每一个小节的价值改为val。问:经过Q次操作后总区间的价值是多少。 1&lt;=n&lt;=1e5 0&lt;=Q&lt;=1e5 算法/数据结构: 线段树 注意使用:long long scanf("%I64d") 吐槽: 3*10e5我觉得不需要长整型,但不知道为甚用int就是错!艹,搞这个点搞了一晚上。 代码: #include&lt;iostream&g

rixc_ruanzhanju的博客 423

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

HDU-1698(线段树入门)

请您先别看着个代码,这个代码是我自己在通过自己对线段树的了解,自己写的... 那不是一般的烂...是经过我无数的改正才改过来的 希望大家不要借鉴哦,,一会等我看看,别人的代码,然后再整理整理,出个漂亮的代码.嘿嘿   这个是超时的.... #include #include #include #include int N; struct Node{ int left; int

李硕 843

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Just a Hook (线段树)

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 leng...

YOONGI 447

Just a Hook HDU - 1698 线段树(懒标记)

给定 N, Q,代表序列有 N 个元素,他们的初始值皆是 1。接下來 Q 行,每行有三个数字 X, Y, Z,代表将序列中 X 到 Y 的元素值改成 Z。多組测试,第一个数字 T 代表有几组测试。对于每一组测试,第一行会输入一个数字 N (1

lishuangzhi的博客 205

Just a Hook(区间修改)

题目链接: Just a Hook 大致题意: 给定一个n, 对于区间[1, n]有如下操作: 选定l, r, 把[l, r]区间全部修改为数值c 最后输出[1, n]的区间和 解题思路: 区间修改 + 根结点查询 AC代码: #include &lt;bits/stdc++.h&gt; using namespace std; typedef long long ll; const int N = 1e5 + 10; int n, m; struct node { int l, r; int s

qq_49494204的博客 337

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): 25593    Accepted Submission(s): 12778 Problem Description In the game of D

你真的介意真的在乎真的想要真的渴望的话你一定能够做到 297

HDU 1698 - Just a Hook

题目地址 : http://acm.hdu.edu.cn/showproblem.php?pid=1698   线段树入门题。。。   近期重新写了一遍,就放了上来。   #include #include #define ll (v<<1) #define rr (v<<1|1) #define mmid ((r+l)>>1) using namespace std;

诳人居 449

hdu 2124 简单贪心

Problem Description Long time ago , Kitty lived in a small village. The air was fresh and the scenery was very beautiful. The only thing that troubled her is the typhoon.When the typhoon came, everyth

wtml 436

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

题目传送:Just a Hook 思路:线段树,成段替换, 区间求和。成段更新时,注意延迟标记的作用,它就是用来暂停往下更新来达到节省时间的,然后每次更新每个节点的子节点之前都要判断是否需要往下更新。 AC代码: #include #include #include #include #include #include #include #include #i

Never say never 1649

HDU简单题第四波2090——2099

题意:都是中文题目,不再赘述。 HDU 2090 Code:

u014086857的专栏 528

HDU - 1698 Just a Hook(线段树)

HDU - 1698 Just a Hook #include&lt;cstdio&gt; #include&lt;cstring&gt; const int N = 100010; struct Node { int l,r; int sum,lazy; }tr[N*4]; void pushup(int u) { tr[u].sum=tr[u&lt;&lt;1].sum+tr[u&lt;&lt;1|1].sum; } void pushdown(int u) { Node &amp;root=

00后的博客 281

HDU 1698 Just a Hook

http://acm.hdu.edu.cn/showproblem.php?pid=1698 题意:给一个序列,初始值都是1,有多组测试数据,每个数据序列长度为n,有m个操作,每个操作给出x,y,c,表示把[x,y]区间的值改为c,最后询问序列总和

qq_35752161的博客 201
上一篇: 【poj 1691】Painting A Board
下一篇: 【poj 3461】 Oulipo 中文题意&题解&代码(C++)
WilliamCode
博客等级 码龄11年 118粉丝 105原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值