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. 

InputThe input consists of several test cases. The first line of the input is the number of the cases. There are no more than 10 cases. 
For each case, the first line contains an integer N, 1<=N<=100,000, which is the number of the sticks of Pudge’s meat hook and the second line contains an integer Q, 0<=Q<=100,000, which is the number of the operations. 
Next Q lines, each line contains three integers X, Y, 1<=X<=Y<=N, Z, 1<=Z<=3, which defines an operation: change the sticks numbered from X to Y into the metal kind Z, where Z=1 represents the cupreous kind, Z=2 represents the silver kind and Z=3 represents the golden kind. 
OutputFor each case, print a number in a line representing the total value of the hook after the operations. Use the format in the example. 
Sample Input

1
10
2
1 5 2
5 9 3

Sample Output

Case 1: The total value of the hook is 24.
 #include<iostream>
 #include<cstdio>
 #include<cstring>
 #define ll long long
 using namespace std;
 *1e5+;
 struct t
 {
     ll l,r,sum,lazy,len;
 } tree[amn];
 ll num[amn];
 void push_up(int rt)
 {
     tree[rt].sum=tree[rt<<].sum+tree[rt<<|].sum;
 }
 void push_down(int rt,int l,int r)
 {
     if(tree[rt].lazy)
     {
         ;
         tree[rt<<].lazy=tree[rt<<|].lazy=tree[rt].lazy;
         tree[rt<<].sum=tree[rt<<].lazy*(mid-l+);///左区间长度
         tree[rt<<|].sum=tree[rt<<|].lazy*(r-(mid+)+);///右区间长度
         tree[rt].lazy=;
     }
     return ;
 }
 void build(int rt,ll l,ll r)
 {
     tree[rt].l=l,tree[rt].r=r;
     tree[rt].len=r-l+;
     tree[rt].lazy=;
     if(tree[rt].l==tree[rt].r)
     {
         tree[rt].sum=num[l];
         return ;
     }
     ll mid=(l+r)/;
     build(rt<<,l,mid);
     build(rt<<|,mid+,r);
     push_up(rt);
 }
 void updata(int rt,ll l, ll r,ll L,ll R,ll val)
 {
     ;///区间中点
     if(l>=L&&r<=R)
     {
         tree[rt].lazy=val;
         tree[rt].sum=tree[rt].lazy*tree[rt].len;
         return ;
     }
     push_down(rt,l,r);
     ,l,mid,L,R,val);///若L<=mid,则搜左孩子,若R<mid,则搜右孩子
     if(mid<R)updata(rt<<1|1,mid+1,r,L,R,val);
     push_up(rt);
 }
 int main()
 {
     int t,n,q,x,y,z;
     cin>>t;
     ; ca<=t; ca++)
     {
         scanf("%d%d",&n,&q);
         ; i<=n; i++)num[i]=;
         if(q)
         {
             build(,,n);
             ; i<=q; i++)
             {
                 scanf("%d%d%d",&x,&y,&z);
                 updata(,,n,x,y,z);
             }
             printf(].sum);
         }
         else
         {
             printf();
         }
     }
 }

HDU-1698-Just a Hook-线段树区间修改的更多相关文章

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

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

  2. (简单) HDU 1698 Just a Hook , 线段树+区间更新。

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

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

  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 1698 Just a Hook 线段树区间更新、

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

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

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

  8. HDU 1698 just a hook 线段树,区间定值,求和

    Just a Hook Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1 ...

  9. HDU 1698 Just a Hook 线段树+lazy-target 区间刷新

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

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

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

随机推荐

  1. python--线程同步原语

    Threading模块是python3里面的多线程模块,模块内集成了许多的类,其中包括Thread,Condition,Event,Lock,Rlock,Semaphore,Timer等等.下面这篇文 ...

  2. 深圳市共创力咨询为某大型上市企业提供两天的UCD内训与辅导服务!

    2017年5月23和24日两天,深圳市共创力咨询为国内某大型上市企业提供了为期两天的内训与辅导服务.本次执行培训与辅导任务的是UCD(基于用户体验的设计)资深顾问蔷薇女士.蔷薇老师分别从UCD理论.U ...

  3. html之css选择器学习

    相关内容: 什么是css选择器 标签选择器 类选择器 id选择器 并集选择器(分组选择器) 交集选择器 后代选择器 子标签选择器 属性选择器 相邻兄弟选择器 伪类选择器 伪元素选择器(伪对象选择器) ...

  4. MyBatis笔记----MyBatis查询表全部的两种方法:XML与注解

    查询单条信息的在 http://www.cnblogs.com/tk55/p/6659285.html  已经有了 XML 修改UserMapper.xml <?xml version=&quo ...

  5. [20190130]删除tab$记录的恢复2.txt

    [20190130]删除tab$记录的恢复2.txt --//前面链接写好了脚本,开始测试删除后的恢复.千万不要在生产系统做这样的测试!!--//参考链接:http://blog.itpub.net/ ...

  6. [20170612]FOR ALL COLUMNS SIZE repeat(12c).txt

    [20170612]FOR ALL COLUMNS SIZE repeat(12c).txt --//昨天看了https://jonathanlewis.wordpress.com/2017/06/0 ...

  7. mssql sqlserver 验证整型函数分享

    转自:http://www.maomao365.com/?p=6227 摘要: 下文将制作一个isnumber验证整型的函数,供在sql脚本中做数值判断,如下所示: 例: 实现原理:判断 是否包含特殊 ...

  8. 【MM系列】SAP基本计量单位更改

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP基本计量单位更改   前言部分 ...

  9. C#实现CRC校验

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web; ...

  10. 多文档界面的实现(DotNetBar的superTabControl)

    private void FormMain_Load(object sender, EventArgs e) { superTabControl2.Tabs.Clear(); timer1.Start ...