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. php 常用的JS

      function doit(){ var sel_val=$("#type").val(); if (sel_val=='') { $("#bigClassId1&q ...

  2. 快学Scala-第三章 数组相关操作

    知识点: 1.定长数组 Array val nums = new Array[Int](10) //10个整数的数组,所有元素初始化为0 val a = new Array[String](10) / ...

  3. 快学Scala-第一章 基础

    知识点: Scala程序并不是一个解释器,实际发生的是,你输入的内容被快速的编译成字节码,然后这段字节码交由Java虚拟机执行. 以val定义的值是一个常量,以var定义的值是一个变量,声明值或变量但 ...

  4. linux下环境变量PS1设置

    PS1变量中提示符各项含义:   \d :代表日期,格式为weekday month date,例如:Wed Dec 12 \H :完整的主机名称.例如:hostname是debian.linux \ ...

  5. 转:WebDriver(Selenium2) 处理可能存在的JS弹出框

    在自动化测试过程中,有些情况下我们会遇到一些潜在的Javascript弹出框.(即某些条件下才会出现,不是固定出现),然后如果当这种弹出框出现,我们没有加以处理,WebDriver将无法进行下一步的操 ...

  6. mysql 创建数据 utf8

    CREATE DATABASE db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

  7. c# 执行js的方法

    http://www.cnblogs.com/wuhuacong/archive/2010/11/08/1871866.html 为了有效阻止恶意用户的攻击,一般登录都会采用验证码方式方式处理登录,类 ...

  8. 白话解释IIS并发连接数

    做负载均衡的时候会发现有很多并发数的参数.其中有一个"IIS并发连接数"是我们要关注的. 假设"IIS并发连接数"显示为1000,这并不代表有1000个客户端在 ...

  9. Repeater嵌套gridview

    前台:<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSour ...

  10. C#获取IPv4代码

    using System; using System.Collections.Generic; using System.Collections.Specialized; using System.C ...