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

n个数初始每个数的价值为1,接下来有m个更新,每次x,y,z 把x,y区间的数的价值更新为z(1<=z<=3),问更新完后的总价值。

线段树的区间更新,需要用到延迟标记,简单来说就是每次更新的时候不要更新到底,用延迟标记使得更新延迟到下次需要更新或者询问的时候.

这题只需要输出总区间的信息,即直接输出1结点的信息.

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
//#pragma comment(linker, "/STACK:102400000,102400000")
#define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 100010
#define maxv 210
#define mod 1000000000
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int sum[maxn<<];
int col[maxn<<]; void PushUp(int rt)
{
sum[rt]=sum[rt<<]+sum[rt<<|];
} void PushDown(int rt,int m)
{
if(col[rt])
{
col[rt<<]=col[rt<<|]=col[rt];
sum[rt<<]=(m-(m>>))*col[rt];
sum[rt<<|]=(m>>)*col[rt];
col[rt]=;
}
} void build(int l,int r,int rt)
{
col[rt]=;
sum[rt]=;
if(l==r) return;
int m=(l+r)>>;
build(lson);
build(rson);
PushUp(rt);
} void update(int L,int R,int c,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
col[rt]=c;
sum[rt]=c*(r-l+);
return;
}
PushDown(rt,r-l+);
int m=(l+r)>>;
if(L<=m) update(L,R,c,lson);
if(R>m) update(L,R,c,rson);
PushUp(rt);
}
int main()
{
//freopen("a.txt","r",stdin);
int t,n,m,a,b,c,j=;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
build(,n,);
for(int i=;i<m;i++)
{
scanf("%d%d%d",&a,&b,&c);
update(a,b,c,,n,);
}
printf("Case %d: The total value of the hook is %d.\n",j++,sum[]);
}
return ;
}

hdu - 1689 Just a Hook (线段树区间更新)的更多相关文章

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

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

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

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

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

  4. HDU 1698 Just a Hook 线段树区间更新、

    来谈谈自己对延迟标记(lazy标记)的理解吧. lazy标记的主要作用是尽可能的降低时间复杂度. 这样说吧. 如果你不用lazy标记,那么你对于一个区间更新的话是要对其所有的子区间都更新一次,但如果用 ...

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

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

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

  7. HDU 1556 Color the ball(线段树区间更新)

    Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...

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

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

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

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

随机推荐

  1. ABP教程(二)- 将ABP在本地运行起来

    上一篇 我们介绍了什么是ABP,这一篇我们通过原作者的”简单任务系统”例子,演示如何运用ABP开发项目 从模板创建空的web应用程序 ABP提供了一个启动模板用于新建的项目(尽管你能手动地创建项目并且 ...

  2. A8通用权限框架

  3. $.extend(x,y); 函数用法介绍。

    第一篇资料:  转自: https://www.cnblogs.com/yuqingfamily/p/5813650.html 语法:jQuery.extend( [deep ], target, o ...

  4. 前端--1、HTML基础

    web服务 处于应用层的http协议负责的数据传输与解析.位于socket上层,用socket传输http数据时需要在消息开头处声明是http协议/相应http版本 状态码 状态码含义 \r\n\r\ ...

  5. Maven error in eclipse (pom.xml) : Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4

    i wanna make web project using the Maven to import automatically all libraries that i need, so i cho ...

  6. 由于未清除缓存引发的bug

    在写页面的时候,首先引入了本地react.js和react-dom.js 16版本(cjs)的文件,出现如下错误 发现bug后,将本地的react.js和react-dom.js文件改成16.2(um ...

  7. CAS机制总结

    一.简介 CAS机制:(Compare and set)比较和替换 简单来说–>使用一个期望值来和当前变量的值进行比较,如果当前的变量值与我们期望的值相等,就用一个新的值来更新当前变量的值CAS ...

  8. 如何修改MFC的图标

    原文:如何修改MFC的图标 修改左上角的图标和任务栏里图标 在对话框构造函数中 CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/) : CDialog(CTestD ...

  9. 给SVN控制的项目添加忽略文件/文件夹

    忽略目录其实有些像建立一个文件夹,但却不放入版本控制.如果不加入版本控制又会在svn status命令中显示出来,很不方便,所以可以设置本文件夹属性,让它既加入版本控制,又忽略其变化 未加入控制的文件 ...

  10. 打印出A到Z的所有字符,使用char和int转换

    public class Demo14{ //A到Z的所有字符,使用char和int转换 public static void main(String[] args) { for(int i = 65 ...