(简单) HDU 1698 Just a Hook , 线段树+区间更新。

时间:2021-12-01 10:05:31

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.

  

  题目大意就是给你一排棒子,初始都是铁的,然后改变其中一部分为别的,最后问总价值和。

  典型的线段树区间更新问题。

代码如下:

#include<iostream>
#include<cstdio> #define lson L,M,po*2
#define rson M+1,R,po*2+1 using namespace std; int COL[*];
int BIT[*]; void pushUP(int po)
{
BIT[po]=BIT[po*]+BIT[po*+];
} void pushDown(int po,int len)
{
if(COL[po])
{
BIT[po*]=(len-(len/))*COL[po];
BIT[po*+]=(len/)*COL[po];
COL[po*]=COL[po*+]=COL[po];
COL[po]=;
}
} void build_tree(int L,int R,int po)
{
BIT[po]=(R-L+);
COL[po]=; if(L==R)
return; int M=(L+R)/; build_tree(lson);
build_tree(rson);
} void update(int ul,int ur,int type,int L,int R,int po)
{
if(ul<=L&&ur>=R)
{
BIT[po]=type*(R-L+);
COL[po]=type; return;
} pushDown(po,(R-L+)); int M=(L+R)/; if(ul<=M)
update(ul,ur,type,lson);
if(ur>M)
update(ul,ur,type,rson); pushUP(po);
} int main()
{
int T;
int N,M;
int a,b,t;
cin>>T; for(int ii=;ii<=T;++ii)
{
scanf("%d",&N);
build_tree(,N,); scanf("%d",&M); for(int i=;i<M;++i)
{
scanf("%d %d %d",&a,&b,&t);
update(a,b,t,,N,);
} printf("Case %d: The total value of the hook is %d.\n",ii,BIT[]);
} return ;
}

(简单) HDU 1698 Just a Hook , 线段树+区间更新。的更多相关文章

  1. HDU 1698 Just a Hook&lpar;线段树区间更新查询&rpar;

    描述 In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes ...

  2. HDU 1698 Just a Hook 线段树区间更新、

    来谈谈自己对延迟标记(lazy标记)的理解吧. lazy标记的主要作用是尽可能的降低时间复杂度. 这样说吧. 如果你不用lazy标记,那么你对于一个区间更新的话是要对其所有的子区间都更新一次,但如果用 ...

  3. HDU 1698 Just a Hook&lpar;线段树 区间替换&rpar;

    Just a Hook [题目链接]Just a Hook [题目类型]线段树 区间替换 &题解: 线段树 区间替换 和区间求和 模板题 只不过不需要查询 题里只问了全部区间的和,所以seg[ ...

  4. &lbrack;HDU&rsqb; 1698 Just a Hook &lbrack;线段树区间替换&rsqb;

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. HDU 1698 Just a Hook&lpar;线段树区间替换)

    题目地址:pid=1698">HDU 1698 区间替换裸题.相同利用lazy延迟标记数组,这里仅仅是当lazy下放的时候把以下的lazy也所有改成lazy就好了. 代码例如以下: # ...

  6. hdu - 1689 Just a Hook &lpar;线段树区间更新&rpar;

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 n个数初始每个数的价值为1,接下来有m个更新,每次x,y,z 把x,y区间的数的价值更新为z(1<= ...

  7. HDU&period;1689 Just a Hook &lpar;线段树 区间替换 区间总和&rpar;

    HDU.1689 Just a Hook (线段树 区间替换 区间总和) 题意分析 一开始叶子节点均为1,操作为将[L,R]区间全部替换成C,求总区间[1,N]和 线段树维护区间和 . 建树的时候初始 ...

  8. HDU&period;1556 Color the ball &lpar;线段树 区间更新 单点查询&rpar;

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

  9. Just a Hook 线段树 区间更新

    Just a Hook In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of t ...

随机推荐

  1. unity 协程

    StartCoroutine在unity3d的帮助中叫做协程,意思就是启动一个辅助的线程. 在C#中直接有Thread这个线程,但是在unity中有些元素是不能操作的.这个时候可以使用协程来完成. 使 ...

  2. 记一道有意思的算法题Rotate Image(旋转图像)

    题出自https://leetcode.com/problems/rotate-image/ 内容为: You are given an n x n 2D matrix representing an ...

  3. YAML初探

    http://www.cnblogs.com/chwkai/archive/2009/03/01/249924.html 1 概念YAML是一种人们可以轻松阅读的数据序列化格式,并且它非常适合对动态编 ...

  4. Android SlidingMenu侧滑菜单使用

    把下载的侧滑菜单压缩包打开,会有一个library文件夹,在eclipse中import existing android code into workspace,导入library文件夹,并且选择作 ...

  5. Oracle报错:ORA-01747&colon; user&period;table&period;column&comma; table&period;column 或列说明无效

    1.检查sql书写正确性 2.如果sql书写正确,则是由于数据库列名起的不好引起的,名字用到了数据库的关键字. 如果列很多,又不好确定是哪个列名使用了关键字,以下建议可供参考: 我用以下方法定位 se ...

  6. Cocos2d-X 2&period;2嵌入MFC的子窗口

    1.在cocos2dx目录下创建基于对话框的MFC工程,对话框中间放一个Picture控件 2.添加cocos2dx的相关头文件包含路径.库包含路径和依赖项,可以参考其他cocos工程设置 3.选中P ...

  7. P2564 &lbrack;SCOI2009&rsqb;生日礼物(尺取法)

    P2564 [SCOI2009]生日礼物 三个字.尺取法......... 坐标按x轴排序. 蓝后尺取一下.......... #include<iostream> #include&lt ...

  8. MySQL 加锁处理分析 ---非常牛逼

    http://hedengcheng.com/?p=771 mysql lock in share mode 和 select for update 2016年09月28日 10:23:32 阅读数: ...

  9. textbox显示定位到最后一行(最新一行)

    this.textBox1.Select(this.txtMsgInfo.TextLength, 0); this.textBox1.ScrollToCaret();

  10. 【ZooKeeper】单机伪集群搭建&lpar;适用于mac&rpar;

    1.配置 .zookeeper下载地址:http://apache.mirrors.lucidnetworks.net/zookeeper/ 可以选择需要的版本,我下载的是zookeeper-3.4. ...