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

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

  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cstring>
  5. #include <climits>
  6. #include <complex>
  7. #include <fstream>
  8. #include <cassert>
  9. #include <cstdio>
  10. #include <bitset>
  11. #include <vector>
  12. #include <deque>
  13. #include <queue>
  14. #include <stack>
  15. #include <ctime>
  16. #include <set>
  17. #include <map>
  18. #include <cmath>
  19.  
  20. using namespace std;
  21.  
  22. #define fr first
  23. #define sc second
  24. #define pb(a) push_back(a)
  25. #define Rint(a) scanf("%d", &a)
  26. #define Rll(a) scanf("%I64d", &a)
  27. #define Rs(a) scanf("%s", a)
  28. #define FRead() freopen("in", "r", stdin)
  29. #define FWrite() freopen("out", "w", stdout)
  30. #define Rep(i, len) for(int i = 0; i < (len); i++)
  31. #define For(i, a, len) for(int i = (a); i < (len); i++)
  32. #define Cls(a) memset((a), 0, sizeof(a))
  33. #define Full(a) memset((a), 0x7f7f, sizeof(a))
  34.  
  35. typedef struct Node {
  36. int lo, hi;
  37. Node() {}
  38. Node(int l, int h) : lo(l), hi(h) {}
  39. }Node;
  40.  
  41. #define lrt rt << 1
  42. #define rrt rt << 1 | 1
  43. const int maxn = ;
  44. int sum[maxn<<];
  45. int add[maxn<<];
  46. int n, q;
  47.  
  48. void pushUP(int rt) {
  49. sum[rt] = sum[lrt] + sum[rrt];
  50. }
  51.  
  52. void pushDOWN(int rt, int m) {
  53. if(add[rt]) {
  54. add[lrt] = add[rrt] = add[rt];
  55. sum[lrt] = (m - (m >> )) * add[rrt];
  56. sum[rrt] = (m >> ) * add[lrt];
  57. add[rt] = ;
  58. }
  59. }
  60.  
  61. void build(int l, int r, int rt) {
  62. add[rt] = ;
  63. sum[rt] = ;
  64. if(l == r) return;
  65. int m = (l + r) >> ;
  66. build(l, m, lrt);
  67. build(m+, r, rrt);
  68. pushUP(rt);
  69. }
  70.  
  71. void update(int L, int R, int c, int l, int r, int rt) {
  72. if(l >= L && R >= r) {
  73. add[rt] = c;
  74. sum[rt] = int(c * (r - l + ));
  75. return;
  76. }
  77. pushDOWN(rt, r-l+);
  78. int m = (l + r) >> ;
  79. int ret = ;
  80. if(m >= L) update(L, R, c, l, m, lrt);
  81. if(m < R) update(L, R, c, m+, r, rrt);
  82. pushUP(rt);
  83. }
  84.  
  85. int main() {
  86. // FRead();
  87. int T, _ = ;
  88. int x, y, z;
  89. Rint(T);
  90. while(T--) {
  91. Rint(n); Rint(q);
  92. build(, n, );
  93. Rep(i, q) {
  94. Rint(x); Rint(y); Rint(z);
  95. update(x, y, z, , n, );
  96. }
  97. printf("Case %d: The total value of the hook is %d.\n", _++, sum[]);
  98. }
  99. return ;
  100. }

[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. Google history

    传说,硅谷的公司在和微软的竞争中一直处于下风,不论在市场,人才,还是在打官司上,直到婴儿巨人Baby Giant谷歌的出现,历史才出现前所未有的改变.Google以一个强大的挑战者的身份出现在人们的视 ...

  2. [resource]Python机器学习库

    reference: http://qxde01.blog.163.com/blog/static/67335744201368101922991/ Python在科学计算领域,有两个重要的扩展模块: ...

  3. HDU 2821 Pusher

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2821 首先,题目描述给的链接游戏很好玩,建议先玩几关,后面越玩越难,我索性把这道题A了,也就相当于通关 ...

  4. 在线最优化求解(Online Optimization)之三:FOBOS

    在线最优化求解(Online Optimization)之三:FOBOS FOBOS (Forward-Backward Splitting)是由John Duchi和Yoram Singer提出的[ ...

  5. State of Hyperparameter Selection

    State of Hyperparameter Selection DANIEL SALTIEL VIEW NOTEBOOK Historically hyperparameter determina ...

  6. VS2010字体设置+推荐字体

    字体的设置在工具->选项->环境->字体和颜色. 相信大家在用VS2010的时候都会觉得默认的字体不是很好看,尤其是看的时间长了以后,更是累眼睛,这里推荐一个字体,个人感觉像是加粗加 ...

  7. hadoop浅尝 hadoop与hbase交互

    在安装好hbase之后,运行一个与hadoop无关的纯hbase程序成功了. 接着写一个hadoop与hbase进行交互的小程序,这个程序的运行方法依然与前文相同, 即导出jar文件在shell下运行 ...

  8. JsRender系列demo(4)-if else

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  9. CentOS中基于不同版本安装重复包的解决方案

    http://blog.chinaunix.net/uid-21710705-id-3039675.html

  10. hdu 1288 Hat's Tea

    这个要慢慢理解…… ;}