1. /*
    区间更新
    */
    #include <cstdio>
  2. #include <algorithm>
  3. using namespace std;
  4. #define lson l , m , rt << 1
  5. #define rson m + 1 , r , rt << 1 | 1
  6. const int maxn = ;
  7. int h , w , n;
  8. int col[maxn<<];
  9. int sum[maxn<<];
  10. void PushUp(int rt) {
  11. sum[rt] = sum[rt<<] + sum[rt<<|];
  12. }
  13. void PushDown(int rt,int m) {
  14. if (col[rt]) {
  15. col[rt<<] = col[rt<<|] = col[rt];
  16. sum[rt<<] = (m - (m >> )) * col[rt];
  17. sum[rt<<|] = (m >> ) * col[rt];
  18. col[rt] = ;
  19. }
  20. }
  21. void build(int l,int r,int rt) {
  22. col[rt] = ;
  23. sum[rt] = ;
  24. if (l == r) return ;
  25. int m = (l + r) >> ;
  26. build(lson);
  27. build(rson);
  28. PushUp(rt);
  29. }
  30. void update(int L,int R,int c,int l,int r,int rt) {
  31. if (L <= l && r <= R) {
  32. col[rt] = c;
  33. sum[rt] = c * (r - l + );
  34. return ;
  35. }
  36. PushDown(rt , r - l + );
  37. int m = (l + r) >> ;
  38. if (L <= m) update(L , R , c , lson);
  39. if (R > m) update(L , R , c , rson);
  40. PushUp(rt);
  41. }
  42. int main() {
  43. int T , n , m;
  44. scanf("%d",&T);
  45. for (int cas = ; cas <= T ; cas ++) {
  46. scanf("%d%d",&n,&m);
  47. build( , n , )
  48. while (m --) {
  49. int a , b , c;
  50. scanf("%d%d%d",&a,&b,&c);
  51. update(a , b , c , , n , );
  52. }
  53. printf("Case %d: The total value of the hook is %d.\n",cas , sum[]);
  54. }
  55. return ;
  56. }

hdu1698的更多相关文章

  1. hdu1698(线段树的区间替换)

    HDU1698 #include <bits/stdc++.h> using namespace std; #define Maxn 1001000*4 struct Node{ int ...

  2. hdu1698 线段树区间更新

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

  3. 线段树---成段更新hdu1698 Just a Hook

    hdu1698 Just a Hook 题意:O(-1) 思路:O(-1) 线段树功能:update:成段替换 (由于只query一次总区间,所以可以直接输出1结点的信息) 题意:给一组棍子染色,不同 ...

  4. HDU1698 Just a Hook —— 线段树 区间染色

    题目链接:https://vjudge.net/problem/HDU-1698 In the game of DotA, Pudge’s meat hook is actually the most ...

  5. Just a Hook(HDU1698 线段树的简单应用)

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

  6. HDU-1698 JUST A HOOK 线段树

    最近刚学线段树,做了些经典题目来练手 Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...

  7. HDU1698 Just a Hook

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

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

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

  9. HDU1698 Just a Hook (区间更新)

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

  10. 【线段树成段更新-模板】【HDU1698】Just a Hook

    题意 Q个操作,将l,r 的值改为w 问最后1,n的sum 为多少 成段更新(通常这对初学者来说是一道坎),需要用到延迟标记(或者说懒惰标记),简单来说就是每次更新的时候不要更新到底,用延迟标记使得更 ...

随机推荐

  1. Java_myBatis_全局配置文件

    mybatis主要需要配置的项: 1.properties  配置文件的“环境变量”键值对 2.typeAliases  输入输出数据的类型 3.mappers  映射配置文件 下面看看实例: < ...

  2. Cloud9 开发环境部署

    安装和部署 cloud9 云端开发环境 简介 Cloud9 是亚马逊发布的一款基于云端的开发环境. AWS Cloud9 是一种基于云的集成开发环境 (IDE),您只需要一个浏览器,即可编写.运行和调 ...

  3. Docker部署Consul集群

    服务介绍 Consul是一种分布式.高可用.支持水平扩展的服务注册与发现工具.包含的特性有:服务发现.健康检查.键值存储.多数据中心和服务管理页面等. 官方架构设计图: 图中包含两个Consul数据中 ...

  4. jmeter使用正则表达式匹配多个中的响应结果

    一.背景: 同一个正则表达式匹配多个响应结果值,之前都是添加多个正则表达式,一个一个去获取需要的值,比较麻烦:今天尝试了一下用一个正则表达式获取响应中所有需要的值,使用这种方式也能够获取多个结果中指定 ...

  5. ext中grid根据数据不同显示不同样式

    核心代码: var clsRender = function(value){ if (value == 'male') { return "<span style='color:red ...

  6. Linux - sort 排序

    -t # 指定排序时所用的栏位分隔字符 -n # 依照数值的大小排序 -r # 以相反的顺序来排序 -f # 排序时,将小写字母视为大写字母 -d # 排序时,处理英文字母.数字及空格字符外,忽略其他 ...

  7. Cpp读文件、CString转String、String转CString

    场景 C++读取文件 技术点 读取文件 fstream提供了三个类,用来实现c++对文件的操作.(文件的创建.读.写). ifstream -- 从已有的文件读入 ofstream -- 向文件写内容 ...

  8. Protobuf使用手册

    Protobuf使用手册 第1章 定义.proto 文件 首先我们需要编写一个 proto 文件,定义我们程序中需要处理的结构化数据,在 protobuf 的术语中,结构化数据被称为 Message. ...

  9. ubuntu 安装lightgbm

    前提:安装好git.cmake 1. 安装lightgbm git clone --recursive https://github.com/Microsoft/LightGBM 2. 编译 下载好的 ...

  10. TCP建立流程 【转】

    解决TCP连接数过多的问题 TCP状态迁移,CLOSE_WAIT & FIN_WAIT2 的问题 TCP状态迁移 大家对netstat -a命令很熟悉,但是,你有没有注意到STATE一栏呢,基 ...