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. linux的学习系列 8---进程管理

    当我们运行程序时,Linux会为程序创建一个特殊的环境,该环境包含程序运行需要的所有资源,以保证程序能够独立运行,不受其他程序的干扰.这个特殊的环境就称为进程. 每个 Linux 命令都与系统中的程序 ...

  2. 文本格式ANSI,Unicode等有什么区别

    首先DBCS是亚洲的字符集,包含了ANSI,ANSI也就是ASCII值为0-255之间的字符,当字符为ANSI时,存放于文件中占用的是一个字节.如果是非ANSI的呢,则占用两字节.用VB的ASC函数可 ...

  3. jquery 中 $('div','li')

    要搞清楚$('div','li') 和 $('div , li') 和 $('div li') 区别$('div','li')是$(子,父),是从父节点里找子,而不是找li外面的div $('div ...

  4. Listview多条目展示

    //---------------主要是适配器里面------------------------------------- package com.bwie.test.adapter;import ...

  5. Jenkins设置Poll SCM

    */5 * * * *  (每5分钟执行一次) 0 20 * * *   每天 20点执行定时build # every fifteen minutes (perhaps at :07, :22, : ...

  6. mapreduce 依赖组合

    mport java.io.IOException;import java.util.StringTokenizer; import org.apache.hadoop.conf.Configurat ...

  7. Linux学习 -- Shell编程 -- 流程控制

    if语句 单分支 if [ 条件判断式 ]; then 程序 fi 或者 if [ 条件判断式 ] then 程序 fi 例子: 双分支 if [ 条件判断式 ] then 程序 else 程序 fi ...

  8. STM32F4xx FPU的设置

    原文:http://blog.csdn.net/dlutxie/article/details/7980389 浮点运算一直是定点CPU的难题,比如一个简单的1.1+1.1,定点CPU必须要按照IEE ...

  9. 删除MySQL二进制日志

    服务器上的120G SSD硬盘空间用了92%,检查后发现,原来是 MySQL的二进制日志没有及时清除,占用了大量的空间, 于是直接用命令:reset master 一把删干净了. 1 reset ma ...

  10. SEO优化之 主页上加上nofollow

    <a href=http://www.主页.cn/ rel=”nofollow”>这里是锚文字</a> <光年日志分析系统>来分析抓取比较多的是哪个网页,没用的no ...