题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698

陈题,更新后查询所有叶节点的和。撸一遍模版,形成自己的风格。

 #include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; #define fr first
#define sc second
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%I64d", &a)
#define Rs(a) scanf("%s", a)
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Full(a) memset((a), 0x7f7f, sizeof(a)) typedef struct Node {
int lo, hi;
Node() {}
Node(int l, int h) : lo(l), hi(h) {}
}Node; #define lrt rt << 1
#define rrt rt << 1 | 1
const int maxn = ;
int sum[maxn<<];
int add[maxn<<];
int n, q; void pushUP(int rt) {
sum[rt] = sum[lrt] + sum[rrt];
} void pushDOWN(int rt, int m) {
if(add[rt]) {
add[lrt] = add[rrt] = add[rt];
sum[lrt] = (m - (m >> )) * add[rrt];
sum[rrt] = (m >> ) * add[lrt];
add[rt] = ;
}
} void build(int l, int r, int rt) {
add[rt] = ;
sum[rt] = ;
if(l == r) return;
int m = (l + r) >> ;
build(l, m, lrt);
build(m+, r, rrt);
pushUP(rt);
} void update(int L, int R, int c, int l, int r, int rt) {
if(l >= L && R >= r) {
add[rt] = c;
sum[rt] = int(c * (r - l + ));
return;
}
pushDOWN(rt, r-l+);
int m = (l + r) >> ;
int ret = ;
if(m >= L) update(L, R, c, l, m, lrt);
if(m < R) update(L, R, c, m+, r, rrt);
pushUP(rt);
} int main() {
// FRead();
int T, _ = ;
int x, y, z;
Rint(T);
while(T--) {
Rint(n); Rint(q);
build(, n, );
Rep(i, q) {
Rint(x); Rint(y); Rint(z);
update(x, y, z, , n, );
}
printf("Case %d: The total value of the hook is %d.\n", _++, sum[]);
}
return ;
}

[HDOJ1698]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. 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 ...

  4. 【原创】hdu1698 Just a Hook(线段树→区间更新,区间查询)

    学习线段树第二天,这道题属于第二简单的线段树,第一简单是单点更新,这个属于区间更新. 区间更新就是lazy思想,我来按照自己浅薄的理解谈谈lazy思想: 就是在数据结构中,树形结构可以线性存储(线性表 ...

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

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

  6. hdu1698 Just a hook 线段树区间更新

    题解: 和hdu1166敌兵布阵不同的是 这道题需要区间更新(成段更新). 单点更新不用说了比较简单,区间更新的话,如果每次都更新到底的话,有点费时间. 这里就体现了线段树的另一个重要思想:延迟标记. ...

  7. HDU1698:Just a Hook(线段树区间更新)

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

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

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

  9. hdu1698 Just a Hook (线段树区间更新 懒惰标记)

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

  10. hdu-------(1698)Just a Hook(线段树区间更新)

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

随机推荐

  1. 【开发记录】iOS中使用 Reachability 检测网络

    如果你想在iOS程序中提供一仅在wifi网络下使用(Reeder),或者在没有网络状态下提供离线模式(Evernote).那么你会使用到Reachability来实现网络检测. 写本文的目的 了解Re ...

  2. npm,grunt,less,sass,typescript

    typescript   http://www.typescriptlang.org sass   http://sass-lang.com/ less http://lesscss.org/ bow ...

  3. cocos2dx中的用户数据的管理

    提供了专门的类:CCUserDefault用来管理,且提供了单例方法:sharedUserDefault() 1.会在默认路径cocos2d-x-2.2.3\projects\Hello\proj.w ...

  4. 计划:怎样理解水平集方法 ITK Level set V4 框架介绍

    简易解释:在曲面中插入一个平面所形成的轮廓,即是该轮廓的水平集表示,可见,该轮廓的水平集表示有多个.对于图像分割,在图像力的驱动下曲面进行更新. 轮廓的数学表达有隐式和显式两种表达.用曲面演化代替Fr ...

  5. SQL Server 2008之数据库大型应用解决方案总结

    着互联网应用的广泛普及,海量数据的存储和访问成为了系统设计的瓶颈问题.对于一个大型的互联网应用,每天百万级甚至上亿的PV无疑对数据库造成了相当高的负载.对于系统的稳定性和扩展性造成了极大的问题. 一. ...

  6. mysql 的存储过程调试软件

    免费下载链接:http://download.csdn.net/detail/meiyoudao/6371137  需要注册 调试还是 F10 类似的

  7. oracle 11g行转列 列转行

    行转列: SELECT *   FROM   src_table   UNPIVOT (param_value FOR param_name IN (product_color AS 'product ...

  8. angular-file-upload API angular文件上传插件

    官方例子 : http://nervgh.github.io/pages/angular-file-upload/examples/simple/ ===Directives=== nvFileSel ...

  9. BZOJ 1051: [HAOI2006]受欢迎的牛 强连通缩点

    题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=1051 题解: 强连通缩点得到DAG图,将图转置一下,对入度为零的点跑dfs看看能不能访问 ...

  10. 解决Maven默认仓库没有的jar下载(二)

    前言: 在 “解决Maven不能下载“oracle.aspectjweaver.com.springsource.net.sf.cglib”jar(http://www.cnblogs.com/wql ...