【线段树】 hdu1698 Just a Hook

别再对着手册发愁了!手把手教你读懂MIPI-DSI初始化命令(以Rockchip平台为例) 本文深入解析MIPI-DSI初始化命令在Rockchip平台的应用,帮助嵌入式工程师快速掌握LCD屏幕调试技巧。从协议基础到实战指南,详细拆解命令格式、DCS与Generic命令的区别,并提供Rockchip平台的调试全流程与高级技巧,解决常见显示问题。 阅读详情

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

//区间段内的数进行整体的更新
#include<cstdio>
#include<cstring>
using namespace std;
#define MAX 100005
int sum[MAX<<2];
void push_up(int idx)
{
    sum[idx]=(sum[idx<<1]==sum[idx<<1|1])?sum[idx<<1]:-1;
}
void build(int l,int r,int idx)//建树
{
    if(l==r)
    {
        sum[idx]=1;
        return;
    }
    int mid=(l+r)>>1;
    build(l,mid,idx<<1);
    build(mid+1,r,idx<<1|1);
    push_up(idx);
    return;
}
void updata(int l,int r,int idx,int p,int a,int b)//更新
{
    if(a<=l&&r<=b)
    {
        sum[idx]=p;
        return;
    }
    if(sum[idx]>0)
        sum[idx<<1]=sum[idx<<1|1]=sum[idx];
    int mid=(l+r)>>1;
    if(a<=mid&&sum[idx<<1]!=p) updata(l,mid,idx<<1,p,a,b);
    if(b>mid&&sum[idx<<1|1]!=p) updata(mid+1,r,idx<<1|1,p,a,b);
    push_up(idx);
}
int query(int l,int r,int idx,int a,int b)//查询
{
    if(sum[idx]>0) return sum[idx]*(r-l+1);
    int mid=(l+r)>>1;
    int res=0;
    if(a<=mid) res+=query(l,mid,idx<<1,a,b);
    if(b>mid)  res+=query(mid+1,r,idx<<1|1,a,b);
    return res;
}
int main()
{
    int cas,n,q,a,b,p;
    scanf("%d",&cas);
    for(int t=1;t<=cas;++t)
    {
        scanf("%d%d",&n,&q);
        build(1,n,1);
        for(;q--;)
        {
            scanf("%d%d%d",&a,&b,&p);
            updata(1,n,1,p,a,b);
        }
        printf("Case %d: The total value of the hook is %d.\n",t,query(1,n,1,1,n));
    }
    return 0;
}




多角度模板匹配的模板创建技巧 基于形状的模板匹配多角度创建技巧 阅读详情

相关推荐

高通量测序数据分析:RNA-seq

深度测序相关数据库与数据格式 SRA toolkit 一、NCBI 和EBI、DDBJ组成INSDC,数据内容相同所以找NCBI就行。 (一)NCBI常用数据库 GenBank:遗传序列数据库,收集了所有公开的DNA序列及其注释 GEO (Gene Expression Omnibus) :收集整理各种表达芯片数据,后来加入了甲基化、lncRNA、miRNA、CNV等其他芯片,还有高通量测序数据...

qq_41134363的博客 3万+

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

PX4飞控CAN总线通信深度配置:从menuconfig到驱动加载的完整指南

本文详细解析了PX4飞控中CAN总线通信的深度配置流程,从menuconfig选项设置到驱动加载的完整指南。涵盖硬件抽象层、驱动层和应用层的配置细节,提供实际验证方法和故障排查技巧,帮助开发者高效实现CAN通信,特别适用于无人机和机器人底盘运动控制等场景。

weixin_30374009的博客 501

Just a Hook(区间修改)

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

爱吃猫的鱼~ 460

手把手教你用若依WMS搭建企业级仓库管理系统(Vue+Spring Boot实战)

本文提供了一份基于若依框架(RuoYi)快速搭建企业级仓库管理系统(WMS)的实战指南。详细介绍了从环境准备、项目初始化到核心功能模块(如入库流程、库存管理看板)深度定制的全过程,并涵盖Lodop打印集成、移动端PWA适配及生产环境Docker部署等高级主题,帮助开发者高效构建稳定可用的WMS系统。

weixin_29015899的博客 564

图像去噪实战:Noise2Noise与Noise2Void在医学影像中的应用(附代码)

本文深入探讨了Noise2Noise与Noise2Void在医学影像去噪中的革命性应用,通过自监督学习技术有效解决临床数据配对难题。文章提供详细的代码实现和临床部署方案,展示如何提升低剂量CT、MRI等影像的诊断质量,特别适用于辐射敏感场景和急诊快速处理。

weixin_29092579的博客 242

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 446

YOLOv8-Pose 姿态识别 RK3588 实战:从模型训练到 RKNN 部署,精度与推理速度双提升

本教程从YOLOv8-pose模型的姿态识别训练,到RK3588的边缘量化部署,为你打造了一套“高精度+高实时性+低成本”的人体姿态分析解决方案。无论是健身动作纠正、智能安防行为检测,还是工业人员姿态监控,这套技术都能直接复用——你只需替换数据集与业务逻辑,即可快速落地专属的边缘AI姿态识别系统。如果你在实践中遇到任何卡点,欢迎随时交流。记住,人体姿态识别的价值在于“关键点准、推理快、部署易”,而这三者的平衡,正是你通过本教程能掌握的核心能力。

FJN110的博客 364

HDU 1698 Just a Hook【线段树】 题解

目录1.题目2.代码 1.题目 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.

林深不见鹿 的博客 288

华为od 面试八股文_Python_05_含答案

华为od 面试八股文_Python_05_含答案

MISAYAONE的博客 2565

道路场景分割:车道线、可行驶区域与路沿检测

道路场景分割:车道线、可行驶区域与路沿检测​ ,人工智能,计算机视觉,大模型,AI,文章围绕道路场景分割展开,涵盖车道线、可行驶区域与路沿检测。介绍了基本概念、重要性,各部分检测的类型、方法、难点及解决思路,还涉及技术融合、数据集、评价指标、发展趋势、应用案例、代码示例、不同天气处理、实际问题与方案、实现流程、相关技术工具、教育研究应用、产业前景、伦理安全问题及学习资源等,全面阐述了道路场景分割的多方面内容,为相关学习和研究提供了丰富信息。

不踩坑,不知道坑有多深;不总结,踩过的坑白踩。 22万+

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

华为OD机试真题:明日之星选举 (Java/Py/C/ C++/JS/GO)

华为OD机试(机考)双机位C卷 【明日之星选举】,提供Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试 - 明日之星选举。

qq_45776114的博客 919

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

WINCC7.3破解文件

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

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

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

根据大神博客NotOnlySuccess的讲解,这个题目应该是属于线段树应用的第二阶段,也就是“成段更新”。大神博客已经有代码了,可能由于本题目不是很难所以没有过多的注释,如果是新手还是不容易看懂。所以这里就在啰嗦讲解一点吧。 题目:hdu 1698 Just a Hook 题目大意:dota中的屠夫(英雄)有一个钩子,钩子是连续的,现在假设钩子编号是从1到n,每个钩子有三种状态,分别对应的值

nyist_jiang 962

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

HDU 1698 Just a Hook(线段树:区间set,区间查询)

HDU 1698 Just a Hook(线段树:区间set,区间查询) 分析:线段树区间set基本操作,详情看刘汝佳训练指南。 //HDU 1698 线段树 区间set 区间查询 #include #include #include using namespace std; #define lson i*2,l,m #define rson i*2+1,m+1,r const int MA

code 1363

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

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

题目传送门 1 /* 2 线段树-成段更新:第一题!只要更新区间,输出总长度就行了 3 虽然是超级裸题,但是用自己的风格写出来,还是很开心的:) 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cmath> ...

weixin_30533797的博客 66

hdu 1698 Just A Hook 线段树的一道题

关于线段树以前也有过接触,不过忘了,重新回顾一下,线段树是用二叉树来实现的。 关于线段树的概念,这个blog写的很详细,大家可以看一下http://www.cnblogs.com/shuaiwhu/archive/2012/04/22/2464583.html hdu 1698 Just A Hook 这题题意是屠夫的钩子为n的长度,每段的材质都可以改变,一开始都是铜材质的,经过q次变化后求

ddmike2015的博客 442

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

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

窦小雨的小点子 310

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

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

Joel 253

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

Venishel的博客 563

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

wyjwyl的专栏 371

【原创】hdu1698 Just a Hook(线段树→区间更新,区间查询)

【原创】hdu1698 Just a Hook(线段树→区间更新,区间查询) 学习线段树第二天,这道题属于第二简单的线段树,第一简单是单点更新,这个属于区间更新。 区间更新就是lazy思想,我来按照自己浅薄的理解谈谈lazy思想:   就是在数据结构中,树形结构可以线性存储(线性表)也可以树状存储(链表) 树形typedef struct...

swallowblank的博客 186

hdu1698 Just a Hook 线段树区间更新,延时标记

传送门:hdu1698 Just a Hook 题目大意有三种钩子,分为铜,银,金,对应的价值分别为1,2,3,一共有n个钩子,初始的时候每个钩子的都是铜的。先做如下操作对x到y区间的钩子改变为z价值(1~3)的,最后求出所有钩子的总价值。 输入:第一行输入t组测试数据 然后测试数据的第一行表示表示有多少个钩子 下面一行输入一个整数q表示有多少种操作 下面的q行是每一次操作是,x,y,z,表

woshinannan的专栏 476

【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
上一篇: 【二分匹配】 poj2060 Taxi Cab Scheme
下一篇: 【线段树】 hdu1166 敌兵布阵
ACM_Ted
博客等级 码龄15年 122粉丝 208原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值