线段树专题—HDU1698 Just a Hook

《UVM实战》学习笔记——第三章UVM基础 uvm基础,常见的派生类,config db机制,打印信息等 阅读详情

题意:t组数据,给一个n,m表示n长度的钩和m次操作,初始钩子的每单位长度的价值为1,接下来输入 x,y,k 的操作把钩子[x,y]区间的价值替换为k,求m次操作后钩子的价值为多少


分析:成段替换,最后只要求第一个区间就可以了,使用不用写query询问


代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include<vector>
#pragma comment(linker,"/STACK:1024000000,1024000000")
using namespace std;
const int maxn = 1e5+5;
int sum[maxn*4];
int lazy[maxn*4];
void up(int rt){
    sum[rt]=sum[rt<<1]+sum[rt<<1|1];
}
void down(int l,int r,int rt){
    if(!lazy[rt]) return;
    int mid=(l+r)>>1;
    lazy[rt<<1]=lazy[rt];lazy[rt<<1|1]=lazy[rt];
    sum[rt<<1]=lazy[rt]*(mid-l+1);
    sum[rt<<1|1]=lazy[rt]*(r-mid);
    lazy[rt]=0;
}
void build(int l,int r,int rt){
    sum[rt]=lazy[rt]=0;
    if(l==r){
        sum[rt]=1;
        return;
    }
    int mid=(l+r)>>1;
    build(l,mid,rt<<1);
    build(mid+1,r,rt<<1|1);
    up(rt);
}
void update(int L,int R,int k,int l,int r,int rt){
    if(L<=l&&r<=R){
        sum[rt]=k*(r-l+1);
        lazy[rt]=k;
        return;
    }
    down(l,r,rt);
    int mid=(l+r)>>1;
    if(L<=mid) update(L,R,k,l,mid,rt<<1);
    if(R>mid) update(L,R,k,mid+1,r,rt<<1|1);
    up(rt);
}
int main()
{
    int t;
    scanf("%d",&t);
    for(int cas=1;cas<=t;cas++){
        int n,m;
        scanf("%d%d",&n,&m);
        build(1,n,1);
        while(m--){
            int x,y,k;
            scanf("%d%d%d",&x,&y,&k);
            update(x,y,k,1,n,1);
        }
        printf("Case %d: The total value of the hook is %d.\n",cas,sum[1]);
    }
}


Aspice的理解 ASPICE 是由汽车行业的主要公司和组织合作开发的,包括德国汽车工业联合会(VDA)和国际汽车工作组(Automotive SIG)。其目标是通过标准化的软件开发流程,提高汽车电子系统的软件质量和可靠性。 阅读详情

相关推荐

Conformal LEC逻辑等价性检查介绍和参考脚本

分为三个产品:Conformal L、Conformal XL、Conformal GXL。L是功能性检查,XL支持复杂数据通路的综合和APR优化,GXL支持定制的stdcell和定制memory的检查。Cadence Conformal Equivalence Checker,就是常说的LEC,可以用来验证RTL、门级网表、甚至spice网表的逻辑等价性。do文件是conformal的脚本文件,可以由综合工具(RTL Compiler/Genus)自己产生(write_do_lec),也可以手写。

NanDigits的博客 7256

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

李!的博客 813

C#粘包和分包问题及解决方法

一:通过图解法来描述一下分包和粘包,这样客户更清晰直观的了解:  下面对上面的图进行解释:  1.正常情况:如果Socket Client 发送的数据包,在Socket Server端也是一个一个完整接收的,那个就不会出现粘包和分包情况,数据正常读取。  2.粘包情况:Socket Client发送的数据包,在客户端发送和服务器接收的情况下都有可能发送,因为客户端发送的数据都是发送的一个缓冲...

weixin_42033401的博客 7767

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

matlab 三维绘图 抛光,瓷砖抛光过程建模与仿真

:瓷砖抛 光过程 建模与仿真朱 成 就(广 东工业大学 机 电工程 学院, 广东广州 )摘要 :瓷砖的抛磨影响 因素众 多 ,实际磨削加工时容易出现漏抛 、返抛现象 。对陶瓷抛光机磨头进行运动学分析 ,并基于不 同粒度号 的磨 粒在一定压力下的加工深度模型 ,探讨抛光机磨 头转 速 、横梁摆动频率 、传送速度对瓷砖抛光加工表 面均匀性 的影响,然 后结合 磨削机理使 用 对陶瓷抛光过程进行仿真 ...

weixin_36331058的博客 748

学习Fidder主要掌握的技术——流量篡改

本文介绍了Fiddler工具的三种常用调试方法:1)本地映射-通过保存修改JSON响应文件实现接口数据模拟;2)Composer接口调试-通过修改请求参数快速测试接口异常处理;3)断点调试-在请求/响应过程中拦截并修改数据。这三种方法分别适用于前端开发、接口测试和健壮性验证等场景,能够有效提高调试效率。操作步骤包括保存响应、修改数据、配置规则等关键环节,并提供了详细的界面操作指引。

2301_79022773的博客 353

Just a Hook(区间修改)

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

爱吃猫的鱼~ 460

【超简单】一文入门在Ubuntu系统使用GitHub

Github是基于git的代码仓库,对于开发项目的科研者或者工程师,代码仓库都是不可多得的版本控制与多端编程工具,今天这篇文章带你轻松Github入门,简单的项目本文的操作足矣。

a13337649640的博客 5236

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

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

Cosmic_Tree的博客 283

Python量化入门:用pytdx获取800个交易日K线数据的完整指南(附代码)

本文为Python量化交易初学者提供了使用pytdx库免费获取股票日线级别K线数据的完整指南。文章详细介绍了从环境搭建、单只股票数据获取,到构建健壮的批量下载器、数据清洗与验证,再到基础分析与可视化的全流程,并附有可直接运行的代码示例,帮助读者快速建立本地股票数据库。

weixin_29050513的博客 1466

【30】软考软件设计师——UML类图与用例图满分精讲|下午第3题常考核心

本文是《软件设计师·50讲通关|从零基础到工程师职称》专栏第30篇,聚焦**模块四:应用技术(下午题)第3道高频大题**,UML建模是历年下午必考核心,单题分值稳定10~12分。全文深度拆解两大核心UML图表:**类图**与**用例图**,超详细讲解类图三层结构、可见性修饰符、五大核心关系(泛化/关联/依赖/聚合/组合)的判定标准与绘图规范;吃透用例图参与者、系统边界、三大关系(包含/扩展/泛化)的底层逻辑,搭配独家**关系秒杀口诀、标准绘图模板、真题改错技巧**;全文适配补图、判断关系、分析场景、纠错优化

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 573

[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的博客 269

从 Chat 提示词到可运行 Fiori 应用,ADT for VS Code 正在把 RAP 开发带进 Agent 时代

本文探讨了在VS Code中使用AI辅助进行ABAP RAP开发的新模式。文章指出,传统RAP开发需要手工创建数据库表、CDS视图、行为定义等十多个关联对象,命名和关联关系容易出错。现在通过GitHub Copilot Agent Mode配合ADT MCP Server,开发者可用自然语言描述业务场景直接生成完整的RAP业务对象。这种生成式开发的核心价值在于:1)通过标准化工具接口(MCP)连接ABAP后端,确保生成符合规范的RAP对象;2)能正确处理多实体组合场景下的命名一致性和关联关系;3)保持生成结

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 89

kuangbin专题七 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 length. ...

weixin_30376323的博客 82

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

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

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

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的博客 173

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

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 169

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

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

【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

来日浅谈的博客 634

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

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)

大太阳 736

【线段树】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_ 197

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的博客 2754

【线段树】 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 游乐园 2283

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的博客 161

线段树 Just a hook

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

ontrmhsis 404

【线段树区间更新】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_的博客 231
上一篇: 线段树专题 POJ3468 A Simple Problem with Integers
下一篇: HDU 5375 Gray code(DP)
sin_XF
博客等级 码龄12年 12粉丝 31原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值