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. MVC 5 视图之公用代码

    一.公共模板 1.@RenderBody() 在网站公用部分通过一个占位符@RenderBody()来为网站独立部分预留一个位置.然后私有页面顶部通过@{Layout="公用模板路径&quo ...

  2. mybatis由浅入深day01_3mybatis框架介绍

    3 mybatis框架 3.1 mybatis是什么? mybatis是一个持久层的框架,是apache下的顶级项目. mybatis托管到goole code下,再后来托管到github下(http ...

  3. Mac普通用户修改了/etc/sudoers文件的解决办法

    1.开启 Root 账户 打开“系统偏好设置”,进入“用户与群组”面板,记得把面板左下角的小锁打开,然后选择面板里的“登录选项”.在面板右边你会看到“网络账户服务 器”,点击它旁边的“加入…”按钮,再 ...

  4. python2.0 s12 day2

    s12 day2 视频每节的内容 05 python s12 day2 python编码   1.第一句python代码 python 执行代码的过程 文件读到内存 分析内容 编译字节码  转换机器码 ...

  5. Dubbo注册中心Zookeeper安装步骤

    第一步:安装jdk 第二步:上传zookeeper至Linux 第三步:解压zookeeper安装包(/soft目录是我在根目录下建立的一个用户存放上传安装包的目录),解压命令tar -xvf /so ...

  6. /usr/local/java/jdk1.8.0_11

  7. AndroidのBuild工具之Ant动手实践

    好久没有写博客了,没半年也应该有几个月了.在工作上的项目遇到过很多问题或者说积累了不少经验,曾经都蛮想发到博客留个纪念什么的,不求可以为别人获得点经验技巧,只求在多年后遇到同样的问题可以找到个记录.但 ...

  8. MUI 分享功能(微信、QQ 、朋友圈)

    配置文件:manifest.json plus ->plugins 下边 "share": {/*配置应用使用分享功能,参考http://ask.dcloud.net.cn/ ...

  9. LeetCode——N-Queens

    Description: The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that n ...

  10. Android ImageResizer:inSampleSize

    import android.annotation.TargetApi; import android.content.Context; import android.content.res.Reso ...