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. Struts2框架原理

    Struts2提供了基于MVC应用程序的开发模式,从而使应用程序结构更加清晰,同时也简化了Web应用程序的开发. Struts2的组成结构 主要包括控制器组件(包括核心控制器StrutsPrepare ...

  2. SQL注入与防范

    首先给大家看个例子: 1)小编首先在数据库中建立了一张测试表logintable,表内有一条测试信息: 然后写了个测试程序: package com.java.SqlInject; import ja ...

  3. 【JS基础】类型转换——不同数据类型比较

    小试牛刀 输出下列数据比较结果 [] == 0; //==============================================================true [] == ...

  4. PHP的匿名函数和闭包

    匿名函数 // Example1 $func = function( $param ) { echo $param; }; $func( 'some string' );//输出:some strin ...

  5. 最新的windows xp sp3序列号 xp序列号

    最新的windows xp sp3序列号(绝对可通过正版验证) MRX3F-47B9T-2487J-KWKMF-RPWBY(工行版) 可用(强推此号) QC986-27D34-6M3TY-JJXP9- ...

  6. java笔记----常见的异常

    常见的可控异常 运行时的异常 异常信息的获取

  7. spring4笔记----spring4构造注入

    与设值注入有以下不同,颜色标出 package com.ij34.web; import com.ij34.servce.people; import com.ij34.servce.root; pu ...

  8. 转:Log Explorer使用说明恢复被误删除的数据

    一.介绍 Log Explorer主要用于对MSSQLServer的事物分析和数据恢复.你可以浏览日志.导出数据.恢复被修改或者删除的数据(包括执行过update,delete,drop和trunca ...

  9. 同步下的资源互斥:停运保护(Run-Down Protection)机制

    背景 近期在学习ProcessHacker的源码,Process Hacker是一个免费的.功能强大的"任务管理器",可用于监听系统资源的使用情况,调试软件以及检测恶意程序.使用中 ...

  10. MacOS远程Windows提示:远程桌面连接无法验证您希望连接的计算机的身份

    解决方法: 1.在Windows端,运行输入 “gpedit.msc”,打开本地组策略编辑器 2.依次打开[计算机配置]→[管理模板]→[windows组件]→[远程桌面服务]→[远程桌面会话主机]→ ...