HDU1698 Just a Hook

基于ENVI5.3的Landsat条带去除、辐射定标、大气校正 基于ENVI5.3的Landsat条带去除、辐射定标、大气校正坏带修复辐射定标大气校正 坏带修复 1.下载landsat_gapfill插件,放入“安装目录\Exelis\ENVI53\extensions”,重启ENVI 2. 加载拟处理文件(MTL.txt格式) 3.打开landsat_gapfill 4.选择存放位置并命名文件 5.选择处理文件 辐射定标 1.选择工具Radiometric Calibration 2.选择已修复坏带文件 3.修改参数,选择输出位置及命名文件 大气校正 1 阅读详情

Just a Hook

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



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.
 

Source
2008 “Sunline Cup” National Invitational Contest


对应线段树的区间更新,代码有注释

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAX=100010;
struct seg
{
    int l,r;
    int sum,mark;
}tree[MAX*4];
void pushdown(int k)    //向下传递,延迟操作
{
    int x=tree[k].r-tree[k].l+1;        //求出这个区间的长度
    tree[2*k].mark=tree[2*k+1].mark=tree[k].mark;   //把需要更新的值向下传递
    tree[2*k].sum=(x-(x>>1))*tree[k].mark;  //更新子节点的值
    tree[2*k+1].sum=(x>>1)*tree[k].mark;
    tree[k].mark=0;
}
void build(int l,int r,int k)
{
    tree[k].l=l;
    tree[k].r=r;
    tree[k].mark=0;
    if(l==r)
    {
        tree[k].sum=1;      //初始值是1
        return;
    }
    int mid=(l+r)>>1;
    build(l,mid,2*k);
    build(mid+1,r,2*k+1);
    tree[k].sum=tree[2*k].sum+tree[2*k+1].sum;
}
void insert(int l,int r,int k,int val)
{
    if(tree[k].l>=l&&tree[k].r<=r)     //修改的区间完全包含这个节点的区间
    {
        tree[k].mark=val;      //标记,如需要后面做延迟操作
        tree[k].sum=(tree[k].r-tree[k].l+1)*val;
        return;
    }
    if(tree[k].mark!=0)
        pushdown(k);    //延迟操作,把更新向下传递,只有在需要时才更新子节点,大大提高了效率
    int mid=(tree[k].l+tree[k].r)>>1;
    if(mid>=l)
        insert(l,r,2*k,val);
    if(mid<r)
        insert(l,r,2*k+1,val);
    tree[k].sum=tree[2*k].sum+tree[2*k+1].sum;
}
int query(int l,int r,int k)
{
    if(tree[k].r<l||tree[k].l>r)
        return 0;
    if(tree[k].l>=l&&tree[k].r<=r)
        return tree[k].sum;
    if(tree[k].mark!=0)
        pushdown(k);
    return query(l,r,2*k)+query(l,r,2*k+1);
}
int main()
{
    int t,n,m,x,y,flag=1,a;
    //freopen("in.txt","r",stdin);
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        build(1,n,1);
        while(m--)
        {
            scanf("%d%d%d",&x,&y,&a);
            insert(x,y,1,a);
        }
        printf("Case %d: The total value of the hook is %d.\n",flag++,query(1,n,1));
    }
    return 0;
}


vcenter server6.0上vmware inventory 、virtualvcenter等服务无法开启 描述:一天,vcenter访问不了,因此Windows远程到vcenter server上。相关服务未开启,开启virtualCenter server服务提示相关依赖服务未开启,于是开启依赖项服务Inventory服务报错。然后打算使用 C:\Program Files\VMware\vCenter Server\bin\servcivce-control来开启vmware服务 1.... 阅读详情

相关推荐

XGBoost算法案例 - 红酒品质分类

数据集共包含 11 个特征,共计 3269 条数据. 我们通过训练模型来预测红酒的品质, 品质共有 6 个各类别,分别使用数字: 0、1、2、3、4、5 来表示。

YIAN爱学习的博客 449

[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

从模组到集装箱:手把手拆解一个储能BMS的软硬件架构设计与通信组网

本文深入解析储能BMS的软硬件架构设计与通信组网,从电芯采样到系统集成的全链条技术实现。详细介绍了三级硬件架构(AFE、CMU、BMU)的设计要点,以及软件分层实现中的驱动层、应用层核心算法和通信协议栈。通过实战案例分享CAN网络搭建、调试工具链和系统验证测试经验,为储能系统开发提供实用指导。

weixin_30752699的博客 464

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

AI Pika 生成进击的巨人动漫分镜案例

AI Pika 生成进击的巨人动漫分镜案例 Pika 是一个使用AI生成和编辑视频的平台。

独立开发,substack顶级编辑 2574

libjpeg-turbo图片解码 VS opencv

本文对比了libjpeg-turbo和opencv在图像解码层面的耗时情况,及解码数据是否存在diff

优快云_WHB的博客 834

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

泛微ecology9二次开发-附件上传-安全实践

本文深入探讨了泛微ecology9二次开发中附件上传功能的安全实践。针对原生接口的安全机制,文章提出了同源部署与服务端代理转发两大核心策略,并提供了基于Vue3和Element Plus的完整前端实现代码,重点解决了会话验证、权限控制及文件关联等关键安全问题,确保二次开发应用能安全、稳定地与ecology9系统集成。

qsc9012345的博客 533

惊呆了!Oracle 11g从入门到放弃的保姆级指南(新手必看)

本文为Oracle 11g数据库新手提供了一份详尽的入门指南。内容涵盖从安装配置、SQL*Plus工具使用、核心的SQL增删改查操作,到事务、索引等进阶概念的解析。文章旨在帮助初学者避开常见陷阱,快速掌握这一经典关系型数据库管理系统的基本操作与核心技能,实现从入门到上手。

ooo22的博客 266

单波束与多波束声呐:从原理到应用场景的全面解析

本文全面解析了单波束与多波束声呐的工作原理、核心特点及应用场景。单波束声呐如精准的狙击手,适合高精度需求;多波束声呐则像高效的散弹枪,适用于快速测绘和大面积覆盖。文章还提供了选型指南和前沿发展趋势,帮助用户根据预算和需求选择最适合的声呐技术。

weixin_30872157的博客 221

HDU-1698-Just a Hook

HDU-1698-Just a Hook http://acm.hdu.edu.cn/showproblem.php?pid=1698 还是成段更新线段树 #include<stdio.h> #include<string.h> #include<stdlib.h> #define N 100005 struct cam { int x; int y;...

weixin_30652897的博客 87

从开发到生产:Power APP 的应用和编程实践

一旦您在开发环境中完成了应用程序的开发、调试和测试,就可以将其部署到生产环境中供用户使用。在 Power APP Studio 中,您可以选择将应用程序发布到 Power APP 网关或将其嵌入到其他应用程序中。使用 Power APP Studio 内置的调试工具,您可以逐步执行应用程序并查看变量的值,以确保逻辑的正确性。在上述代码中,我们通过将两个文本输入框(TextInput1 和 TextInput2)中的文本转换为数字,并将它们相加,将结果存储在 Result 变量中。

2301_79326510的博客 1504

hdu1698Just a Hook

http://acm.hdu.edu.cn/showproblem.php?pid=1698 裸的线段树区间更新#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace std; const int maxn=100005;struct Node { int su

skymeteorite 429

efm32 入门.pdf

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

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

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

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

nyist_jiang 962

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

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

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

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

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

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

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

线段树(成段更新) 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

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

词庸 1308

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

Mr.zhou 290
上一篇: POJ3468 A Simple Problem with Integers
下一篇: POJ2777 Count Color
eeeaaaaa
博客等级 码龄12年 2粉丝 155原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值