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

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.

题目大意:输入t,有t组样例,输入n,m,代表n个钩子,m次操作,刚开始钩子的价值为1,通过m来改变区间里每个钩子的价值个人思路:线段树区间更新的裸题,用到延迟标记,还要用scanf printf   不然会超时,还有注意的是数组要开大4倍,证明的话自己百度具体思路看代码
#include<iostream>
#include<string.h>
#include<map>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
const int maxn=1e5+10;
const int maxk=100+10;
const int maxx=1e4+10;
const ll maxe=1000+10;
#define INF 0x3f3f3f3f3f3f
#define Lson l,mid,rt<<1
#define Rson mid+1,r,rt<<1|1
int sum[maxn<<2];
int lazy[maxn<<2];
void Pushup(int rt)
{sum[rt]=sum[rt<<1]+sum[rt<<1|1];
}
void Pushdown(int rt,int c,int m)
{lazy[rt<<1]=c;//向下传递lazy[rt<<1|1]=c;lazy[rt]=0;//取消延迟标记,因为已经向下传递了sum[rt<<1]=(m-(m>>1))*c;sum[rt<<1|1]=(m>>1)*c;
}
void Build(int l,int r,int rt)
{if(l==r){sum[rt]=1;return ;}int mid=(l+r)>>1;if(l<=mid) Build(Lson);if(r>mid) Build(Rson);Pushup(rt);
}
void Updata(int l,int r,int rt,int L,int R,int c)
{if(L<=l&&r<=R){lazy[rt]=c;// 延迟标记,不必现在就把下面的值赋值上去,不然难免浪费时间sum[rt]=(r-l+1)*c;return ;}if(lazy[rt])Pushdown(rt,lazy[rt],r-l+1);//需要用到的话就判断是否有延迟标记int mid=(l+r)>>1;if(L<=mid) Updata(Lson,L,R,c);if(R>mid) Updata(Rson,L,R,c);Pushup(rt);
}
int main()
{int t,ca=1;// cin>>t;scanf("%d",&t);while(t--){memset(lazy,0,sizeof(lazy));int n,m;// cin>>n>>m;scanf("%d%d",&n,&m);Build(1,n,1);for(int i=1;i<=m;i++){int a,b,c;//cin>>a>>b>>c;scanf("%d%d%d",&a,&b,&c);Updata(1,n,1,a,b,c);}printf("Case %d: The total value of the hook is %d.\n",ca++,sum[1]);}return 0;
}

转载于:https://www.cnblogs.com/caijiaming/p/9402593.html

Just a Hook(线段树区间更新)相关推荐

  1. hdu 1698 Just a Hook 线段树区间更新

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 Let us number the consecutive metallic sticks of ...

  2. hdu 1698 Just a Hook(线段树区间更新·经典)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1698 数据:case,n,q,q行x,y,z.在长度为n的hook上进行q次区间更新,把它们的价值改变.最 ...

  3. hdu 1698(线段树区间更新)

    解题思路:线段树区间更新水题. #include<iostream> #include<cstdio> #include<cstring> using namesp ...

  4. POJ 2777 ZOJ 1610 HDU 1698 --线段树--区间更新

    直接将这3题 放一起了  今天在做线段树的东西 这3个都是区间更新的 查询方式互相不同 反正都可以放到一起吧 直接先上链接了 touch me touch me touch me 关于涉及到区间的修改 ...

  5. hdu 5692 Snacks(dfs序+线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5692 解题思路:这道题是树节点的点权更新,而且涉及到子树,常用的思路是利用dfs序,用线段树来对区间进 ...

  6. ZOJ 1610 Count the Colors (线段树区间更新)

    题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...

  7. hdu 3966(树链剖分+线段树区间更新)

    传送门:Problem 3966 https://www.cnblogs.com/violet-acmer/p/9711441.html 学习资料: [1]线段树区间更新:https://blog.c ...

  8. hihoCoder 1080 : 更为复杂的买卖房屋姿势 线段树区间更新

    #1080 : 更为复杂的买卖房屋姿势 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho都是游戏迷,"模拟都市"是他们非常喜欢的一个游戏 ...

  9. CodeForces - 272C Dima and Staircase (线段树区间更新)

    题意: 见以下样例,给出 5 个区间,每个区间的高度已知.一共 4 次操作.每次操作都是从最左边开始向下垒一个宽为 w 高为h 的木块,过程见下图. 问每次垒木块的高度是多少? Input 5 1 2 ...

最新文章

  1. Python学习之路:NumPy初识
  2. 利用getLayoutParams()方法和setLayoutParams()方法
  3. [转]Bing Maps Tile System 学习
  4. eclipse开发java项目_用eclipse 开发java 项目
  5. python不会英语不会数学怎么自学-零基础想自学PYTHON如果补数学怎么补?
  6. 细说PHP:人人都能玩转PHP和MySQL Web开发
  7. EnterpriseLibrary2.0的学习-DAAB
  8. 2021-02-16
  9. 快排,归并(日常复习)
  10. cad插入块_CAD中创建块,有一种最快捷的方式,看看你用过没?
  11. 论文笔记:Connectionist Temporal Classification: Labelling Unsegmented Sequence
  12. ESD问题案例分析-智能手表为例
  13. docker安装php拓展
  14. LightGBM 中文文档
  15. 六、路由(routing)
  16. CentOS 7.2 安装Subversion(SVN)
  17. vb计算机怎么制作,教你如何制作VB的PCode调试器 -电脑资料
  18. 操作系统————应用题
  19. 阿里在人工智能发展治理方向的思考和实践
  20. class.forName

热门文章

  1. ASP.Net中服务器控件的生命周期
  2. 中小企业电子商务如何发展?
  3. python虚拟环境解决不能执行脚本的问题
  4. 算法工程师面试备战笔记9_支持向量机(SVM)中的支持向量是什么意思
  5. GPT Plus Money!B O O M
  6. 站在BERT肩膀上的NLP新秀们(PART I)
  7. 数学建模-14.主成分分析PCA
  8. 一文了解Innodb中的锁
  9. 渗透测试实践(工具使用总结)
  10. 自动化测试学习之路--java 数组