POJ服务器炸了 还没好呢

然后就只能跳掉一些题目了

这题也是成段更新模板题 本来lazy标记不是很明白 后来学长上课讲了一下就知道原理了 回去看看代码很容易就理解了

#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m+1, r, rt << 1 | 1
using namespace std;
typedef long long LL; const int MAXN = 1e5 + ;
LL col[MAXN<<], sum[MAXN<<]; inline void pushup(int rt)
{
sum[rt] = sum[rt<<] + sum[rt<<|];
}
inline void pushdown(int rt, int len)
{
if(col[rt]){
col[rt<<] = col[rt];
col[rt<<|] = col[rt];
sum[rt<<] = (len - (len>>)) * col[rt];
sum[rt<<|] = (len>>) * col[rt];
col[rt] = ;
}
} void build(int l, int r, int rt)
{
col[rt] = ;
if(l == r){
sum[rt] = ;
return;
}
int m = (l + r) >> ;
build(lson);
build(rson);
pushup(rt);
} void update(int L, int R, LL c, int l, int r, int rt)
{
if(L <= l && R >= r){
//printf("Update %d - %d\n", l, r);
col[rt] = c;
sum[rt] = (r - l + ) * c;
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);
} LL query(int L, int R, int l, int r, int rt)
{
if(L <= l && R >= r){
return sum[rt];
}
pushdown(rt, r - l + );
int m = (l + r) >> ;
LL res = ;
if(L <= m) res += query(L, R, lson);
if(R > m) res += query(L, R, rson);
return res;
} int main()
{
int t, n, q;
scanf("%d", &t);
for(int kase = ; kase <= t; kase++){
scanf("%d%d", &n, &q);
build(, n, );
while(q--){
int l, r;
LL c;
scanf("%d%d%I64d", &l, &r, &c);
update(l, r, c, , n, );
}
printf("Case %d: The total value of the hook is %I64d.\n",
kase, query(, n, , n, ));
}
return ;
}

kuangbin_SegTree E (HDU 1698)的更多相关文章

  1. HDU 1698 Just a Hook (线段树区间更新)

    题目链接 题意 : 一个有n段长的金属棍,开始都涂上铜,分段涂成别的,金的值是3,银的值是2,铜的值是1,然后问你最后这n段总共的值是多少. 思路 : 线段树的区间更新.可以理解为线段树成段更新的模板 ...

  2. HDU 1698 just a hook - 带有lazy标记的线段树(用结构体实现)

    2017-08-30 18:54:40 writer:pprp 可以跟上一篇博客做个对比, 这种实现不是很好理解,上一篇比较好理解,但是感觉有的地方不够严密 代码如下: /* @theme:segme ...

  3. HDU 1698 【线段树,区间修改 + 维护区间和】

    题目链接 HDU 1698 Problem Description: In the game of DotA, Pudge’s meat hook is actually the most horri ...

  4. HDU 1698——Just a Hook——————【线段树区间替换、区间求和】

    Just a Hook Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit  ...

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

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

  6. Just a Hook (HDU 1698) 懒惰标记

    Just a Hook (HDU 1698) 题链 每一次都将一个区间整体进行修改,需要用到懒惰标记,懒惰标记的核心在于在查询前才更新,比如将当前点rt标记为col[rt],那么此点的左孩子和右孩子标 ...

  7. hdu 1698 线段树成段更新

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 #include <cstdio> #include <cmath> # ...

  8. HDU 1698 Just a Hook(线段树成段更新)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1698 题目: Problem Description   In the game of DotA, P ...

  9. hdu 1698+poj 3468 (线段树 区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 这个题意翻译起来有点猥琐啊,还是和谐一点吧 和涂颜色差不多,区间初始都为1,然后操作都是将x到y改为z,注 ...

随机推荐

  1. JavaScript为input/textarea自定义hover,focus效果

    <title>JavaScript为input/textarea自定义hover,focus效果</title> <script type="text/java ...

  2. ReactiveCocoa信号使用方法

    最近研究RAC时都是基于UI控件来使用,对单独的signal没有使用过,最近在网上看到一篇文章是关于RAC单独signal的使用.在学习整理后将个人觉得能帮助用于UI控件的一些signal使用方法记录 ...

  3. js修改:before、:after的内容

    一.js控制伪元素content内容 二. --------------2016-7-20 13:34:03-- source:[1]js如何控制伪元素的内容

  4. iOS开发 ReactiveCocoa入门教程 第一部分

    作为一个iOS开发者,你写的每一行代码几乎都是在响应某个事件,例如按钮的点击,收到网络消息,属性的变化(通过KVO)或者用户位置的变化(通过CoreLocation).但是这些事件都用不同的方式来处理 ...

  5. JavaWeb基础: ServletConfig

    基本概念 ServletConfig用于配置Servlet的参数:在Servlet的配置文件中,可以使用一个或者是多个<init-param> 标签为Servlet配置一些初始化参数.当有 ...

  6. xcodebuild

    xcodebuild -workspace /path/union/moon-ios/Moon.xcworkspace -scheme Moon ONLY_ACTIVE_ARCH=NO TARGETE ...

  7. android recyclerview 更新ui

    http://blog.csdn.net/leejizhou/article/details/51179233

  8. jQuery.extend源码深层分析

    在网站的开发中,经常会自己写一些jQuery插件来方便使用,其中自然少不了一个关键的方法->jQuery.extend(),使用这个方法来扩展jQuery对象. 那么今天就来讲讲这个函数的实现原 ...

  9. Swift语言—有趣的字符串连接、数组、字典

    字符串链接:Swift语言中的字符串连接方式本人觉得非常的有趣,变量连接需要用右斜杠,并且变量名要括起来 “\(变量名)”,后面的字符串连接分别用逗号 ‘ , ’ 隔开 数组: Var arr = [ ...

  10. css3 弹框功能样式

    .message-box{ position: fixed; top: 0; right: 0; bottom: 0; left: 0; background-color: rgba(0, 0, 0, ...