Description:  

  In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length.

  Now Pudge wants to do some operations on the hook.

  Let us number the consecutive metallic sticks of the hook from 1 to N. For each operation, Pudge can change the consecutive metallic sticks, numbered from X to Y, into cupreous sticks, silver sticks or golden sticks.
The total value of the hook is calculated as the sum of values of N metallic sticks. More precisely, the value for each kind of stick is calculated as follows:

  For each cupreous stick, the value is 1.
  For each silver stick, the value is 2.
  For each golden stick, the value is 3.

  Pudge wants to know the total value of the hook after performing the operations.
  You may consider the original hook is made up of cupreous sticks.

  

  题目大意就是给你一排棒子,初始都是铁的,然后改变其中一部分为别的,最后问总价值和。

  典型的线段树区间更新问题。

代码如下:

  1. #include<iostream>
  2. #include<cstdio>
  3.  
  4. #define lson L,M,po*2
  5. #define rson M+1,R,po*2+1
  6.  
  7. using namespace std;
  8.  
  9. int COL[*];
  10. int BIT[*];
  11.  
  12. void pushUP(int po)
  13. {
  14. BIT[po]=BIT[po*]+BIT[po*+];
  15. }
  16.  
  17. void pushDown(int po,int len)
  18. {
  19. if(COL[po])
  20. {
  21. BIT[po*]=(len-(len/))*COL[po];
  22. BIT[po*+]=(len/)*COL[po];
  23. COL[po*]=COL[po*+]=COL[po];
  24. COL[po]=;
  25. }
  26. }
  27.  
  28. void build_tree(int L,int R,int po)
  29. {
  30. BIT[po]=(R-L+);
  31. COL[po]=;
  32.  
  33. if(L==R)
  34. return;
  35.  
  36. int M=(L+R)/;
  37.  
  38. build_tree(lson);
  39. build_tree(rson);
  40. }
  41.  
  42. void update(int ul,int ur,int type,int L,int R,int po)
  43. {
  44. if(ul<=L&&ur>=R)
  45. {
  46. BIT[po]=type*(R-L+);
  47. COL[po]=type;
  48.  
  49. return;
  50. }
  51.  
  52. pushDown(po,(R-L+));
  53.  
  54. int M=(L+R)/;
  55.  
  56. if(ul<=M)
  57. update(ul,ur,type,lson);
  58. if(ur>M)
  59. update(ul,ur,type,rson);
  60.  
  61. pushUP(po);
  62. }
  63.  
  64. int main()
  65. {
  66. int T;
  67. int N,M;
  68. int a,b,t;
  69. cin>>T;
  70.  
  71. for(int ii=;ii<=T;++ii)
  72. {
  73. scanf("%d",&N);
  74. build_tree(,N,);
  75.  
  76. scanf("%d",&M);
  77.  
  78. for(int i=;i<M;++i)
  79. {
  80. scanf("%d %d %d",&a,&b,&t);
  81. update(a,b,t,,N,);
  82. }
  83.  
  84. printf("Case %d: The total value of the hook is %d.\n",ii,BIT[]);
  85. }
  86.  
  87. return ;
  88. }

(简单) HDU 1698 Just a Hook , 线段树+区间更新。的更多相关文章

  1. 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 ...

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

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

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

    Just a Hook [题目链接]Just a Hook [题目类型]线段树 区间替换 &题解: 线段树 区间替换 和区间求和 模板题 只不过不需要查询 题里只问了全部区间的和,所以seg[ ...

  4. [HDU] 1698 Just a Hook [线段树区间替换]

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

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

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

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

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

  7. HDU.1689 Just a Hook (线段树 区间替换 区间总和)

    HDU.1689 Just a Hook (线段树 区间替换 区间总和) 题意分析 一开始叶子节点均为1,操作为将[L,R]区间全部替换成C,求总区间[1,N]和 线段树维护区间和 . 建树的时候初始 ...

  8. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

  9. 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 ...

随机推荐

  1. android笔记20170116

    封装http请求类,利用回调机制获取返回值 public interface HttpCallbackListener { void onFinish(String response); void o ...

  2. 2016.10.08--Intel Code Challenge Final Round--D. Dense Subsequence

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  3. Git学习 -- 冲突解决

    当连个分支对统一文件提交了不同修改时,可能会出现冲突,例如: $ git merge feature1 Auto-merging readme.txt CONFLICT (content): Merg ...

  4. hdu_5738_Eureka(脑洞)

    题目链接:hdu_5738_Eureka 题意: 这题感觉说不清楚,坑点有点坑,一不小心就会推出错误的公式,然后最重要的是你还不知道你推错了 题解: 这里贴一个官方的题解 Eureka xjb推导一下 ...

  5. 关于Tcpreplay

    tcpprep -p -o /root/Desktop/ZS/Tcpreplay/cache_test.cache -i /root/Desktop/ZS/Tcpreplay/9.17.pcap tc ...

  6. aspx 文件上传和下载,多文件上传

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MultiFileUpload. ...

  7. 归心似箭,IT达人分享抢票攻略

    [51CTO专稿]随着春节一天天临近,“购票难”的问题也愈发凸显,猎豹.火狐.360等“春运抢票神器”占领了各大网站的重要版面,“技术抢票”成为炙手可热的话题,看看身为程序员的邓以克是如何抢到回家的票 ...

  8. Zigbee协议栈OSAL层API函数【转载】

              OSAL层提供了很多的API来对整个的协议栈进行管理.主要有下面的几类:信息管理.任务同步.时间管理.中断管理.任务管理.内存管理.电源管理以及非易失存储管理.看到这些管理是不是感 ...

  9. FZU Problem 2221 RunningMan(贪心)

    一开始就跑偏了,耽误了很长时间,我和队友都想到博弈上去了...我严重怀疑自己被前几个博弈题给洗脑了...贪心的做法其实就是我们分两种情况,因为A先出,所以B在第一组可以选择是赢或输,如果要输,那直接不 ...

  10. Direct3D中的绘制

    1.顶点缓存和索引缓存 一个顶点缓存是一个包含顶点数据的连续内存空间:一个索引缓存是一个包含索引数据的连续内存空间. 顶点缓存用接口IDirect3DVertexBuffer9表示:索引缓存用接口ID ...