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




高斯-约当(Gauss-Jordan)消元法——c++代码实现 具体算法的详细原理请参照此篇博客:高斯-约当(Gauss-Jordan)消元法下面是具体c++代码,不保证程序最优化,提供一个可行的程序,供大家改进,同时感谢大家提意见。——大神勿喷呀,我是一个小菜鸟~void Guss_Jordan(int n,double *a)//阶数n 系数矩阵a { double*a_temp = new double[n*n * 2];//a与单位矩阵的组合 阅读详情

相关推荐

常用的串口通信工具MobaXterm、Bus Hound、SScom等

本文介绍了四种PC端串口通信工具的功能和使用方法:MobaXterm支持SSH、FTP、串口等多种协议;Bus Hound用于监控CAN和串口数据;SScom专为串口和网口通信设计;ScriptCommunicator可进行串口通信并绘制波形图。每种工具都有详细的操作步骤图示,包括参数设置、数据监控等关键功能,并提供了官方和个人下载地址。这些工具各有特点,适用于不同的串口通信和数据分析场景。

sanqima的专栏 2571

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

SAP 物料账前期没有运行的解决方法

If you use the actual costing (material ledger), you must have completely closed all period-end closing operations in the actual costing for the penultimate period prior to the period shift. Use the '...

含笑饮砒霜死后更嚣张 3322

Just a Hook(区间修改)

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

爱吃猫的鱼~ 461

【全解析 | PTA】浙大版《Python 程序设计》题目集-第一章

Python浙大版PTA题解

wzhh_的博客 5533

CanMV K230实战:用MicroPython玩转AI视觉识别(附完整代码)

本文详细介绍了如何使用MicroPython在CanMV K230开发板上实现AI视觉识别,包括环境搭建、摄像头配置、模型部署及优化技巧。通过实战案例(如智能门禁和工业分拣机器人),展示如何快速开发低门槛的嵌入式AI应用,特别适合初学者和嵌入式开发者。

x8y9z0的博客 1152

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

matlab电偶极子源码,电偶极子的MATLAB场模拟

电偶极子周围电场电势分布的MATLAB三维模拟Matlab可以用于模拟四维场的效果,本文以电偶极子的电场和电势场为例展示MATLAB在该方面领域的应用。摘要电偶极子由一个正电荷和一个负电荷组成,其电场和空间电势分布与单电荷相比具有一些重要的特性。本文将给出电场和电势场的近似表达式。这两个量的精确表达式是复杂的,不太常用,因此 MATLAB 被采用来操作精确值和绘制三维分布的远区域, 近区域和一侧区...

weixin_35135480的博客 3155

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

基于ESP32 蓝牙游戏手柄设计

介绍使用 ESP32 并通过 BLE 通信的 设计手持游戏手柄,包含原理图与代码

DT程序员的博客 2170

使用 MATLAB/Simulink + Simscape Electrical 构建一个他励直流电机的启动与制动过程仿真模型

直流电机在工业控制、电动车辆、自动化设备中广泛应用。其中,他励直流电机(Separately Excited DC Motor)因其励磁绕组与电枢绕组分别供电,具有良好的调速性能和启动特性,常用于需要平稳启动和精确控制的场合。在实际应用中,电机的启动过程和制动过程对电网、机械系统以及电机本身都具有重要影响。因此,仿真分析他励直流电机的启动与制动特性,是电机控制设计的重要环节。本文将详细介绍如何使用构建一个他励直流电机的启动与制动过程仿真模型,并通过仿真分析其动态响应。本文详细介绍了如何使用构建一个。

amy_mhd的博客 234

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

YOLO26 多任务统一架构:检测 / 分割 / 姿态 / OBB 设计

YOLO26提出了一种多任务统一架构,整合了目标检测、实例分割、姿态估计和旋转框检测(OBB)四大计算机视觉任务。该架构采用共享Backbone和Neck的设计,配合轻量级任务特定Head,解决了传统方法中多模型并行带来的高开发成本、大内存占用和低推理效率问题。核心设计包括:1)共享特征提取层实现参数复用;2)模块化Head结构支持灵活任务组合;3)统一接口实现单模型多任务处理。实验表明,该架构在保持各任务性能的同时显著提升了系统效率,为多任务视觉系统提供了新的实现范式。

一键难忘的博客 721

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

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

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

IEM模型,地表粗糙度模拟

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

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

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

nyist_jiang 963

efm32 入门.pdf

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

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 1364

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

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

weixin_30533797的博客 67

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_ 199

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

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

Joel 256

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的专栏 372

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

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

swallowblank的博客 188

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

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

woshinannan的专栏 477

【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

hdu 1698 Just a Hook 线段树求解

线段树的一些简单操作

曾经追梦的happy时光 661
上一篇: 【二分匹配】 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、付费专栏及课程。

余额充值