http://acm.hdu.edu.cn/showproblem.php?pid=1698

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.
 
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#define N 1000010
using namespace std;
struct node
{
int l,r,lz,w;
} q[*N];
int n;
void pushup(int rt)
{
q[rt].w=q[rt<<].w+q[rt<<|].w;
}
void pushdown(int rt,int len)
{
if(q[rt].lz)
{
q[rt<<].lz=q[rt].lz;
q[rt<<|].lz=q[rt].lz;
q[rt<<].w=q[rt].lz*(len-(len>>));
q[rt<<|].w=q[rt].lz*(len>>);
q[rt].lz=;
}
}
void build(int l,int r,int rt)
{
q[rt].l=l;
q[rt].r=r;
q[rt].w=;
q[rt].lz=;
if(l==r)
return ;
int mid=(l+r)>>;
build(l,mid,rt<<);
build(mid+,r,rt<<|);
pushup(rt);
return ;
}
void update(int lf,int rf,int l,int r,int rt,int key)
{
if(lf<=l&&rf>=r)
{
q[rt].w=key*(r-l+);
q[rt].lz=key;
return ;
}
pushdown(rt,(r-l+));
int mid=(l+r)>>;
if(lf<=mid) update(lf,rf,l,mid,rt<<,key);
if(rf>mid) update(lf,rf,mid+,r,rt<<|,key);
pushup(rt);
}
int main()
{
int T,m,s1,s2,key;
scanf("%d",&T);
for(int z=; z<=T; z++)
{
scanf("%d",&n);
build(,n,);
scanf("%d",&m);
for(int i=; i<m; i++)
{
scanf("%d%d%d",&s1,&s2,&key);
update(s1,s2,,n,,key);
}
printf("Case %d: The total value of the hook is %d.\n",z,q[].w);
}
}

HDU1698:Just a Hook(线段树区域更新模板题)的更多相关文章

  1. 【原创】hdu1698 Just a Hook(线段树→区间更新,区间查询)

    学习线段树第二天,这道题属于第二简单的线段树,第一简单是单点更新,这个属于区间更新. 区间更新就是lazy思想,我来按照自己浅薄的理解谈谈lazy思想: 就是在数据结构中,树形结构可以线性存储(线性表 ...

  2. hdu1698 Just a hook 线段树区间更新

    题解: 和hdu1166敌兵布阵不同的是 这道题需要区间更新(成段更新). 单点更新不用说了比较简单,区间更新的话,如果每次都更新到底的话,有点费时间. 这里就体现了线段树的另一个重要思想:延迟标记. ...

  3. hdu-------(1698)Just a Hook(线段树区间更新)

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

  4. hdu1698 Just a Hook (线段树区间更新 懒惰标记)

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

  5. FZU Problem 2171 防守阵地 II (线段树区间更新模板题)

    http://acm.fzu.edu.cn/problem.php?pid=2171 成段增减,区间求和.add累加更新的次数. #include <iostream> #include ...

  6. UESTC 1591 An easy problem A【线段树点更新裸题】

    An easy problem A Time Limit: 2000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others ...

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

    Description: In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of ...

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

  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. [java ] java.util.zip.ZipException: error in opening zip file

    严重: Failed to processes JAR found at URL [jar:file:/D:/tools/apache-tomcat-7.0.64_2/webapps/bbs/WEB- ...

  2. android开发源代码分析--多个activity调用多个jni库的方法

    android开发源代码分析--多个activity调用多个jni库的方法 有时候,我们在开发android项目时会遇到须要调用多个native c/jni库文件,下面是本人以前实现过的方法,假设有知 ...

  3. JavaScript------生成Guid方法

    转载: http://blog.csdn.net/limm33/article/details/51536529 代码: function newGuid() { var guid = "& ...

  4. 微信小程序 ui框架(辅助)

    WeUi: https://weui.io/ https://github.com/weui/weui-wxss/ Wa-Ui: https://github.com/liujians/Wa-UI/w ...

  5. hadoop程序MapReduce之MaxTemperature

    需求:求每年当中最高的温度 样本:temp.log 2016080623 2016072330 2015030420 输出结果:2016 30 2015 20 MapReduce分析设计: Mappe ...

  6. Bash Shell 里的各种括号

    天在 SegmentFault 上看到又有人问起关于Shell里各种括号的问题.对于很多玩Shell的人,括号是个很尴尬的问题,用起来没问题,说起来不明白,我在这里总结一下Bash Shell几种括号 ...

  7. 告别C#,进入了下一个阶段的学习啦

    嘿嘿,今天我们结束了C#的基础的学习,开始啦第二个阶段的学习,就是对SQL Server的学习.今天又是一个周一,又是一个新的开始,感觉我们都是一周一周的计算,而不是每天到这个点就是告别了今天的生活啦 ...

  8. cocos2d-x游戏引擎核心之十——网络通信

    一.建立基本的http通信并得到返回信息 1.创建cocos2dx工程 2.项目引用外部库 如果要使用cocos2dx的CCHttpClient来进行网络访问,则需要引入cocos2dx的相关库,详细 ...

  9. php学习二:表达式

    1.  可变变量$$ 在php中,可变变量可以用$$来表示, 代码如下: $name = "zhangSan"; $$name = "liSi"; //相当于$ ...

  10. Objective-c官方文档翻译 类的定义

     类是对象的蓝图. 一个类是描述了对象的行为和属性.例如NSString的一个实例.他的类提供了各种的方法来转化和表示他的内部字符的表示.   每个类的实例都包含了这个类的属性和行为.例如每个NSSt ...