hdu1698 线段树区间更新

C语言实战:最小二乘法在传感器数据校准中的应用(附完整代码) 本文详细介绍了如何使用C语言实现最小二乘法,对传感器数据进行线性校准。通过模拟带噪声的传感器数据,手把手演示了从核心算法实现、参数计算到效果验证的完整流程,并提供了可直接编译运行的完整源码,帮助嵌入式开发者解决传感器数据不准的常见问题,提升系统测量精度。 阅读详情

Just a Hook

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


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.


/*
hdu1698 线段树区间更新
更新到指定区间时打一个标记 ,然后用push_up,push_down对标记进行处理即可
hhh-2016-03-04 20:29:58
*/
#include <algorithm>
#include <cmath>
#include <queue>
#include <iostream>
#include <cstring>
#include <map>
#include <cstdio>
#include <vector>
#include <functional>
#define lson (i<<1)
#define rson ((i<<1)|1)
using namespace std;
typedef long long ll;
const int maxn = 150050;
const int inf = 0x3f3f3f3f;

struct node
{
    int val,sum;
    int l,r;
    int mid()
    {
        return (l+r)>>1;
    }
} tree[maxn<<2];

void push_up(int i)
{
    tree[i].sum = tree[lson].sum + tree[rson].sum;
}

void build(int i,int l,int r)
{
    tree[i].l = l,tree[i].r = r;
    tree[i].val = 0;
    tree[i].sum = 1;
    if(l == r)
    {
        return ;
    }
    build(lson,l,tree[i].mid());
    build(rson,tree[i].mid()+1,r);
    push_up(i);
}

void push_down(int i)
{
    if(tree[i].val)
    {
        tree[lson].val = tree[i].val;
        tree[rson].val = tree[i].val;
        tree[lson].sum = tree[i].val*(tree[lson].r-tree[lson].l+1);
        tree[rson].sum = tree[i].val*(tree[rson].r-tree[rson].l+1);
        tree[i].val = 0;
    }
}


void update(int i,int l,int r,int v)
{
    if(tree[i].l >= l && tree[i].r <= r)
    {
        tree[i].val = v;
        tree[i].sum = v*(tree[i].r-tree[i].l+1);
        return ;
    }
    push_down(i);
    if(l <= tree[i].mid())
        update(lson,l,r,v);
    if(r > tree[i].mid())
        update(rson,l,r,v);
    push_up(i);
}


int main()
{
    int T,n,q;
    int cas = 1;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        scanf("%d",&q);
        build(1,1,n);
        for(int i =1; i <= q; i++)
        {
            int l,r,val;
            scanf("%d%d%d",&l,&r,&val);
            update(1,l,r,val);
        }
        printf("Case %d: The total value of the hook is %d.\n",cas++,tree[1].sum);
    }
    return 0;
}




深入解析雪球网股票行情数据爬取:基于WebSocket与API的实时数据获取技术实践 本文详细介绍了如何使用Python爬虫技术获取雪球网的股票行情数据,涵盖了WebSocket实时数据连接和RESTful API接口调用两种主要技术方案。完整的WebSocket客户端,支持实时行情订阅和数据处理功能丰富的API客户端,支持多种数据类型的获取数据存储和管理系统,使用SQLite进行数据持久化实时监控和预警系统,支持自定义预警规则技术指标计算,提供基本的数据分析功能。 阅读详情

相关推荐

Embarcadero Dev-C++ 6.3安装教程【保姆级】

Embarcadero Dev-C++ 6.3安装教程,保姆级教程~

Thebest_jack的博客 1万+

HDU 1698(线段树,区间更新)

HDU 1698(线段树,区间更新)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

DGY01的博客 483

别再瞎改注册表了!实测Win10/Win11远程桌面60帧的正确姿势(附ToDesk对比)

本文深入解析Windows远程桌面60帧优化的科学方法,揭示常见误区并提供实测有效的解决方案。从版本差异到硬件加速,再到第三方工具对比(如ToDesk),帮助用户避开无效的注册表修改,实现流畅的远程桌面体验。

weixin_33738555的博客 341

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

SAP PCC成本收集器实战:从配置到结算的完整流程解析

本文详细解析了SAP PCC成本收集器从配置到结算的完整流程,特别适用于重复制造行业。通过实战案例和配置要点,帮助用户掌握物料分类账管理、成本中心费用归集及差异分析等核心功能,提升企业生产成本控制效率。

weixin_29251567的博客 895

2024美团秋招硬件开发笔试真题及答案解析

在 Linux 内核的网络设备驱动中,数据链路层的功能通常由网络协议栈的低层(如以太网驱动)实现,而不是作为网络设备驱动的一个独立层次。在 FreeRTOS 中,任务通知(Task Notifications)是一种轻量级的事件传递机制,用于在任务之间或任务与中断之间传递信号。小美正在开发一个简单的密码生成器,其中一个功能是将输入的字符串中的所有字母按字母顺序循环前移一位(即 'a' 变为 'z','B' 变为 'A',以此类推)。它包含了网络设备的各种参数和方法,用于管理网络设备的初始化、配置和操作。

XU157303764的博客 1675

【线段树区间更新】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_的博客 230

等保测评-瀚高数据库

一般适用于等保测评

m0_54146694的博客 1634

线段树区间更新(相对标记)hdu 1698

hdu 1698 (1)线段树区间更新: 分为两种更新方式:绝对标记,相对标记 相对标记:将一个区间内的值+x。 绝对标记:将一个区间内的值全部变为x。 我们在更新区间时是将区间分为若干个子区间进行更新, (eg:在1~13内更新区间2~5,是将前2~5分为2,3~4,5三个区间进行修改,所以修改的复杂度是logn级别的,具体如何 划分区间参见这篇文章) 但是并没有将被...

积少成多,水滴石穿 317

34、木材在家具制造中的应用

本文详细探讨了木材在家具制造中的应用,从木材的选择、加工技术到设计创新和表面处理等方面进行了全面解析,并结合实际案例分析木材家具的市场趋势与未来发展。文章强调了木材家具在功能性、智能化和环保性方面的潜力,展示了其在现代家居生活中的重要地位。

flink9streamer的博客 242

5、硬件工程师笔试面试——上拉电阻、下拉电阻(2025版本)

本文系统介绍了上拉电阻和下拉电阻的原理与应用。上拉电阻通过连接电源确保电路高电平状态,常用于数字电路防抖、OC门驱动等场景;下拉电阻连接地线维持低电平,适用于低电平触发电路。文章详细分析了两种电阻的选择方法、功耗与响应速度的平衡策略,以及在高速信号传输中的影响差异。同时对比了二者的优缺点,并提供了模拟电路中的应用实例。最后给出了电阻值计算的工程方法,为硬件工程师的电路设计提供了实用参考。

XU157303764的博客 2868

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

题目描述HDU 1698 Just a Hook解题思路题目大意: 每段区间有三类状态: 值为1, 2, 3 要求支持下列操作: 1) 修改区间的状态, 然后输出整个区间[1, n]的和 线段树成段更新的入门题, 具体看注释哈~参考代码#include <stdio.h> #define lson rt<<1 #define rson rt<<1|1 #define mid ((l+r) >

FZU_zyt的专栏_(:з」∠)_ 394

23、OpenMP常见用例与标准循环级示例详解

本文详细介绍了OpenMP的三种典型用例:循环级OpenMP、高级OpenMP和MPI+OpenMP,适用于不同层次的并行需求。重点讲解了循环级OpenMP在向量加法、流三元组和模板计算中的应用示例,并探讨了首次触摸优化、线程绑定、NUMA架构影响等关键性能优化策略。通过实际代码演示和性能分析,帮助开发者快速掌握OpenMP的基础并行化方法,并为后续高性能优化提供指导。

fanta的博客 86

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

WINCC7.3破解文件

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

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

HDU1698线段树区间更新

lazy思想: 每次更新只要更新到题目要求的区间即可,然后更新此区间节点data值, 记录tree[num].lazy(等于题目要求更新的值wei), 下次要用到的时候就传递给左右子树,更新左右子树的data值。 并且将当前lazy归0.

363

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

hdu 1698 just a hook(线段树区间更新)

题目连接:hdu 1698区间更新, 线段树维护两个关键值, 一个是col表示颜色,即题目那三种,另一个关键是保存区间和sum,col用延迟标记,即当需要访问到儿子结点的时候才把col传递下去,并且更新儿子结点的sum值代码:#include&lt;cstdio&gt; #define MAXN 100010 struct node{ int left, right, sum, col; }t...

比克大魔王的blog 259

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

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

HDU 1698 【线段树区间更新】

之前一直觉得自己线段树敲得很熟练,然后。。。某天。。。是的,就是我的数据结构周开始的时候我发现。。。我特么才会单点更新是怎么回事!只会区间查找是肿么回事!!摔! 恩。。。就是表达一下弱渣的心情。。。。 区间更新,用到延迟操作。 延迟操作应该是这么回事。线段树的优越性就是体现在,第一是二分查找,第二是区间操作。当我们需要多次对区间进行操作的时候,如果每次都更新每个区间内的每个节点,那么线段树的

The Summer, The Winter 519

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

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

Joel 253

java-HDU1698(线段树的区间更新,和区间查询)

HDU1698: 题目意思: Just a Hook Time Limit: 4000/2000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 49065Accepted Submission(s): 23200 Problem Description ...

weixin_30950887的博客 339

HDU 1698 线段树(区间更新

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

新熊君的博客 666

hdu1698线段树(区间更新)

题目链接just a hook 一个锁链,其组成成部分有三种材料,金银铜,分数为3、2、1,每次可以更换一段的材料,求最后的分数 钩子最多长100,000,操作最多有100,000次,肯定不能暴力-》线段树 延迟标记lazy:每个节点新增加一个标记lazy,每次要更新节点时,不更新到叶节点,记录这个节点是否进行了某种修改(这种修改操作会影响其子节点。 假设要更新的区间为【1,4】,

pmt123456的博客 578

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

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

swallowblank的博客 186

hdu1698(线段树区间更新)

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

dgbxssz959266的博客 210

HDU1698 线段树 区间更新

题意:区间更新及求和。 思路:模板题。#include <iostream> #include <cstring> using namespace std; const int MAXN = 100000 + 10; int sum[MAXN << 2], add[MAXN << 2]; void PushUp(int rt) { sum[rt] = sum[rt << 1] + sum[

ACUNSTOPPABLE 305

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

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

闲停 676
上一篇: hdu 4288 离线线段树+间隔求和
下一篇: hdu2795 线段树 贴广告
Tyuio28
博客等级 码龄11年 12粉丝 279原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值