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

题意:
给出1~n的数,每个数初始为1,每次改变[a,b]的值,最后求1~n的值之和。

思路:

区间更新题目,关于懒惰标记什么的参考这个吧http://blog.sina.com.cn/s/blog_a2dce6b30101l8bi.html,讲得不错的。

 #include<iostream>
#include<cstring>
#include<algorithm>
using namespace std; const int maxn = + ; int n, m; int col[maxn << ]; struct node
{
int l, r;
int n;
}t[maxn << ]; //如果该区间被标记了,说明该区间值改变,需要向下传递
void PushDown(int o, int m)
{
if (col[o])
{
col[o << ] = col[o << | ] = col[o];
t[o << ].n = (m - (m >> ))*col[o];
t[o << | ].n = (m >> )*col[o];
col[o] = ;
}
} void PushUp(int o)
{
t[o].n = t[o << ].n + t[o << | ].n;
} void build(int l, int r, int o)
{
col[o] = ;
t[o].l = l;
t[o].r = r;
t[o].n = ;
if (l == r) return;
int mid = (l + r) / ;
build(l, mid, * o);
build(mid + , r, * o + );
} void update(int l, int r, int x, int o)
{
if (l <= t[o].l && r >= t[o].r)
{
t[o].n = x*(t[o].r - t[o].l + );
col[o] = x;
return;
}
PushDown(o, t[o].r - t[o].l +);
int mid = (t[o].l + t[o].r) / ;
if (l > mid) update(l, r, x, * o + );
else if (r <= mid) update(l, r,x, * o);
else
{
update(l, mid, x, * o);
update(mid + , r, x, * o + );
}
//向上传递
PushUp(o);
} int main()
{
//freopen("D:\\txt.txt", "r", stdin);
int T;
int x, y, k;
int kase = ;
scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
scanf("%d", &m);
build(, n, );
for (int i = ; i <= m; i++)
{
scanf("%d%d%d", &x, &y, &k);
update(x, y, k, );
}
printf("Case %d: The total value of the hook is %d.\n", kase++, t[].n);
}
}

HDU 1698 Just a Hook(线段树:区间更新)的更多相关文章

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

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

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

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

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

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

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

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

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

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

    题目地址:pid=1698">HDU 1698 区间替换裸题.相同利用lazy延迟标记数组,这里仅仅是当lazy下放的时候把以下的lazy也所有改成lazy就好了. 代码例如以下: # ...

  7. hdu - 1689 Just a Hook (线段树区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 n个数初始每个数的价值为1,接下来有m个更新,每次x,y,z 把x,y区间的数的价值更新为z(1<= ...

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

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

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

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

  10. 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. Cisco IOS和IOS XE 新漏洞检测与修复

    Cisco IOS/IOS XE 新漏洞检测与修复 CVE-2018-0150 Cisco IOS XE 存在默认弱口令 漏洞影响: 默认弱口令可以导致攻击者直远程登录控制Cisco设备.受影响版本, ...

  2. 解决jquery在IE下removeAttr不生效的问题

    使用jquery动态操纵DOM的时候在IE下会遇到remvoeAttr() 不生效的问题, 解决的办法是使用prop()方法: var node = $("div>input" ...

  3. 补课:PageRank

    最近连续听到PageRank算法,久闻其名,不闻其详,心里虚得很,今儿补补课. PageRank算法的网络资料非常全面,毕竟是将近二十年的经典算法,算法细节可以参考文末链接,这里简单说说我的理解. P ...

  4. java面向对象(上)

    一.一些重要的概念理解 Java是面向对象的程序设计语言,提供了类,成员变量,方法等的基本功能.类可被认为是一种自定义的数据类型,可以使用类来定义变量,所有使用类定义的变量都是引用变量.它会引用到类的 ...

  5. 02Del.ashx(删除班级)

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using WebHelper ...

  6. 在唯一密钥属性“fileExtension”设置为“.log”时,无法添加类型为“mimeMap”的重复集合项

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkoAAAFfCAIAAAA+snR7AAAgAElEQVR4nOzdZ1xT18PAcf+1VpZaW6

  7. c# 网站 vislual studio

    一.新建 1.新建网站 在 菜单栏-->新建-->项目-->选项编辑语言-->web-->先前版本-> 2.新建母板: *.master文件是母板页文件.添加新项时 ...

  8. [ jQuery ] scrollTop与offset()!

    jQuery scrollTop() 与offset()! 曾经很长一段时间,很多人问我下面一段代码的好处是什么? ;(function($){ //do something })(jQuery); ...

  9. Python开发【笔记】:sort排序大法

    浅谈排序 程序中经常用到排序函数,Python 提供了 sort 和 sorted 函数,一个原地排序,一个返回排序后的新结果 1.参数 函数原型: sort([cmp[, key[, reverse ...

  10. 洛谷P3067 平衡的奶牛群 [USACO12OPEN] meet-in-the-middle

    正解:搜索 解题报告: 先放下传送门QwQ 这题就,双向搜索经典题鸭 首先dfs应该挺好想到的我jio得?就是我们不用记录左右分别得分多少只要记下差值就好了嘛能get? 然后就先搜左边,记录下每个得分 ...