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. unindent does not match any outer indentation level

    报错原因: 空格与tab键混用,一般粘贴代码时会出现 解决方法: 把所有缩进取消,然后用tab键来缩进

  2. zoj 1203 Swordfish prim算法

    #include "stdio.h". #include <iostream> #include<math.h> using namespace std; ...

  3. OpenBSD为何还在用CVS之感

    一个轻松无聊的晚上突然想到一个问题——在当今这个Git大红大紫的时代,OpenBSD为何还在用CVS代码仓库?连他同阵营的FreeBSD都已经改用SVN,宣布逐渐废掉CVS了……问了下google,搜 ...

  4. UML用例图在实际项目中的应用

    对我而言,目前还不能很好地回答这个问题.从来没有在项目中使用过模型,这还是因为以前项目不靠建模也能完成,没有用户,哪来的需求分析呢?UML建模,决定你建的是鸡窝还是摩天大楼,但是我做过的项目甚至连鸡窝 ...

  5. Educational Codeforces Round 14 E.Xor-sequences

    题目链接 分析:K很大,以我现有的极弱的知识储备,大概应该是快速幂了...怎么考虑这个快速幂呢,用到了dp的思想.定义表示从到的合法路径数.那么递推式就是.每次进行这样一次计算,那么序列的长度就会增加 ...

  6. guava学习--FluentIterable

    public class FluentIterableTest { public static void main(String[] args) { Man man1 = new Man(" ...

  7. 前端获取url参数

    function GetQueryString(name){ var reg = new RegExp("(^|&)"+ name +"=([^&]*)( ...

  8. UITableView使用的一些技巧

    1.如果想自己在视图中加一条线,和UITableView的cell的分割线颜色粗细一样,那么可以: UIView *lineView = [[UIView alloc] initWithFrame:C ...

  9. MS Sql server 2008 学习笔记

    数据库中常用的概念 Sql本身是一个服务器,没有界面,Management Studio  只是一个SQL Server管理工具而已,不是服务器. Sql server 在管理工具下面的服务SQL S ...

  10. iOS 图片填充 UIImageView (contentMode)

    掐指算下来做iOS开发也是有两年多的时间了,然后今天一个超级常用的控件让我颜面大跌,于是我准备把自己的丢人行径公之于众.如果您看到我这篇文章时和我一样,也是刚刚知道这项功能,那么您就当收获了一个... ...