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(线段树区间更新查询)

    描述 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(线段树 区间替换)

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

  4. [HDU] 1698 Just a Hook [线段树区间替换]

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

  5. HDU 1698 Just a Hook(线段树区间替换)

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

  6. hdu - 1689 Just a Hook (线段树区间更新)

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

  7. HDU.1689 Just a Hook (线段树 区间替换 区间总和)

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

  8. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    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. ThreadLocal类及常用的线程安全类探究

    1.ThreadLocal类 ThreadLocal是Thread Local Variable的简称,意思是线程局部变量.作用是为每一个使用该变量的线程都提供一个该变量的副本,使每一个线程都能独立操 ...

  2. gradle 构建spring源码时候报错

    这是使用jdk1.7报的错,我卸载1.7后使用1.8 ,就可以了

  3. Loadrunner性能测试分类详(二)

    一.基准测试 有基础的标准,这样能通过对比发现系统的不同点与变化. 1.可以再指定的标准下通过基准测试建立一个性能基准,这样以后当系统的环境.参数发生变化后,再进行一次相同标准下的测试,即可看出变化对 ...

  4. CodeForces 678C Joty and Chocolate

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  5. 使用DTM ( Dynamic Topic Models )进行主题演化实验

    最近想研究下Dynamic Topic Models(DTM),论文看了看,文科生的水平确实是看不懂,那就实验一下吧,正好Blei的主页上也提供了相应的C++工具, http://www.cs.pri ...

  6. 如何获取url访问历史记录

    在院里的群里,有人问了这么一个问题: A页面提交表单到B页面,然后在B页面点了后退,如果在A页面上判断是直接访问的还是后退进去的呢?我不想改B页面. 于是乎本着热心人的想法,我就帮他搞了搞,首先我想到 ...

  7. php报错 Call to undefined function mb_stripos()

    错误原因 没有mbstring扩展 本文只介绍Linux解决办法 方法一 编译PHP的时候 带上--enable-mbstring参数 方法二 进入PHP源码/ext/mbstring目录 ./con ...

  8. 利用transform制作幻灯片

    html代码 <html><head></head><body><div class='hpic'> <ul style=" ...

  9. jquery has deprecated synchronous XMLHTTPRequest

    Like many others, my website is using jquery. When I open the developer tools, I see a warning that ...

  10. AngularJS Front-End App with Cloud Storage Tutorial Part 1: Building a Minimal App in Seven Steps

    原文 : http://www.codeproject.com/Articles/1027709/AngularJS-Front-End-App-with-Cloud-Storage-Tutoria ...